2016-06-16 31 views
1

下面給出的是我所選擇的座標位置如何將選定位置的座標轉換爲php中的long lat?

(31.41804293752012,73.0742385238409),(31.414820024420457,73.07904504239559),(31.419031763657962,73.08410905301571),(31.422877099540145,73.0788304656744)

我想這些座標經度轉換和latitude..kindly幫我這個

我已存儲的各X座標成獨立的數組紐約座標轉換成單獨的數組下面 是我的代碼,會灌輸一些感覺,我在做什麼畢竟... 我只是需要知道如何轉換這些座標lat和長,然後將這些緯度郎街道地址.....

function check($point,$x_cordinates,$y_cordinates,$lat,$lon) 
{ 
    $i=$j=$k=0; 
    for ($i = 0, $j = $point-1; $i < $point; $j = $i++) 
    { 
                         if (($y_cordinates[$i] > $lat_y != ($y_cordinates[$j] > $lat_y)) &&   ($lon_x < ($x_cordinates[$j] - $x_cordinates[$i]) * ($lat_y - $y_cordinates[$i])/($y_cordinates[$j] - $y_cordinates[$i]) + $x_cordinates[$i])) 
       { 
      $k = !$k; 
       } 
    } 
    return $k; 
} 
     $office_id=24; 
     $sql="select office_loc from office where office_id='$office_id'LIMIT 1"; 
     $que=mysql_query($sql); 
     if($que) 
    { 
      $row=mysql_fetch_array($que); 
      $loc=$row['office_loc']; 
      $loc_wdot_rbrac=explode('(',$loc); 
      $loc_wdot_lbrac=str_replace(')', '', $loc_wdot_rbrac); 
      $x_cordinates=array(); 
      $y_cordinates=array(); 
      foreach ($loc_wdot_lbrac as $value) 
     { 
      # code... 
     if (empty($value)) 
     { 
      # code... 
     contine; 
     } 
     $loc_wdot_comma=explode(',',$value); 
     $x_cordinates[]=$loc_wdot_comma[0]; 
     $y_cordinates[]=$loc_wdot_comma[1]; 

     } 
     echo '---- Result x ---- <br /><pre>'; 
     print_r($x_cordinates); 
     echo '</pre>'; 

     echo '---- Result y ---- <br /><pre>'; 
     print_r($y_cordinates); 
     echo '</pre>'; 
     $lat=31.5546; 
     $lon=74.3572; 
     $point=count($x_cordinates); 
     if(check($point,$x_cordinates,$y_cordinates,$lat,$lon)) 
     { 
      echo"inside"; 
     } 
      else 
     { 
      echo"out"; 
     } 


      } 
      else 
     { 
       echo mysql_error(db); 
      } 

,這裏是輸出.....

   ---- Result x ---- 
        Array 
      (
       [0] => 
       [1] => 31.41804293752012 
       [2] => 31.414820024420457 
       [3] => 31.419031763657962 
       [4] => 31.422877099540145 
      ) 
       ---- Result y ---- 
       Array 
       (
       [0] => 
       [1] => 73.0742385238409 
       [2] => 73.07904504239559 
       [3] => 73.08410905301571 
       [4] => 73.0788304656744 
       ) 
         out 
+0

什麼是預期的輸出? – Andreas

+0

@Andreas我已經在代碼下面的問題中發佈了輸出......事情是我想要將這些座標轉換爲lon lat或如果可行然後直接地址 –

+0

您可以嘗試使用Google APi的相同 – Apoorv

回答

0

不知道這會按照你將會得到一個完整匹配的額外數組。

preg_match_all("/\((\d+\.\d+),\s(\d+\.\d+)\)/", $input, $output); 

https://3v4l.org/MjUMA

編輯:爲了得到x和y數組作爲你想在你的編輯,你可以這樣做:https://3v4l.org/Llvpg

$input = "(31.56215484936523, 74.35487531125546),(31.556669638119804, 74.35487531125546),(31.558351803858574, 74.3627717345953),(31.562886186493845, 74.36109803617)"; 

preg_match_all("/\((\d+\.\d+),\s(\d+\.\d+)\)/", $input, $output); 

$x = $output[1]; 
$y = $output[2]; 

Var_dump($x); 
var_dump($y); 
相關問題