试图获得一个位置的经度和纬度

时间:2016-06-15 11:58:44

标签: php

enter image description here到目前为止,这就是我所做的 ![点击这里]获取坐标[点击这里]

( - 33.674068533741966,149.86544609069824),( - 33.578014746143985,150.87069511413574),( - 34.03445260967646,149.98080253601074)

这些是我所选位置的坐标 现在我想将这些值存储到一个没有任何特殊字符和空格的数组中...... 其次,我想将所有x坐标存储在单独的数组中,将y坐标存储在单独的数组中 请帮助我... 我该怎么做?

[1]:http://i.stack.imgur.com/ILSuX.png

1 个答案:

答案 0 :(得分:0)

您可以尝试以下解决方案将坐标转换为数组,并在x和y数组中包含值。

$data = "(-33.674068533741966, 149.86544609069824),(-33.578014746143985, 150.87069511413574),(-34.03445260967646, 149.98080253601074)";
  $data = explode('(',$data);
  $data = str_replace(')','',$data);
  $final_result_x = array();
  $final_result_y = array();
  foreach($data as $d){
    if(empty($d)){
      continue;
    }
    $exploded = explode(',',$d);
    $final_result_x[] = $exploded[0];
    $final_result_y[] = $exploded[1];
  }
    echo '---- Result x ---- <br /><pre>';
    print_r($final_result_x);
    echo '</pre>';

    echo '---- Result y ---- <br /><pre>';
    print_r($final_result_y);
    echo '</pre>';

输出:

---- Result x ---- 
Array
(
    [0] => -33.674068533741966
    [1] => -33.578014746143985
    [2] => -34.03445260967646
)
---- Result y ---- 
Array
(
    [0] =>  149.86544609069824
    [1] =>  150.87069511413574
    [2] =>  149.98080253601074
)