2014-12-13 101 views
0

我想知道如何在地圖點(緯度/經度)(半徑50公里)內添加50公里。如何從點數計算半徑緯度經度

例如:認爲我有緯度-26.462049,經度-49.059448。我想增加100公里上下,並在兩側。我想做一個廣場,並獲得新的點。

我該怎麼做?以及如何從數據庫中獲得所有價值。

回答

0
$radius = 100 //range 
$lat_range = $radius/69.172; 
$lon_range = abs($radius/(cos($latitude) * 69.172)); 
$min_lat = number_format($latitude - $lat_range, "4", ".", ""); 
$max_lat = number_format($latitude + $lat_range, "4", ".", ""); 
$min_lon = number_format($longitude - $lon_range, "4", ".", ""); 
$max_lon = number_format($longitude + $lon_range, "4", ".", ""); 

//查詢這樣的()

$sqlstr = mysql_query("SELECT * FROM `tablename` WHERE (`latitude` BETWEEN '".$min_lat."' AND '".$max_lat."') AND (`longitude` BETWEEN '".$min_lon."' AND '".$max_lon."') "); 
0
 function calculateDistance($latitude1, $longitude1, $latitude2, $longitude2) 
     { 
      $theta = $longitude1 - $longitude2; 
      $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta))); 
      $miles = acos($miles); 
      $miles = rad2deg($miles); 
      $miles = $miles * 60 * 1.1515; 
      return $miles; 
     } 
     $point1_lat = '-26.462049'; 
     $point1_lng = ' -49.059448.'; 

     $point2_lat = currentlatitute; 
     $point2_lng = currentlongitude; 

     $miles = calculateDistance($point1_lat, $point1_lng, $point2_lat,$point2_lng); 
     $kms = $miles * 1.609344; 

     echo $kms; 
相關問題