我想知道如何向地图点(纬度/经度)添加50公里(半径50公里)。
例如:想想我有纬度-26.462049,经度-49.059448。我想向上,向下和侧面增加100公里。我想做一个正方形并得到新的分数。
我该怎么做?以及如何从数据库中获取所有价值。
答案 0 :(得分: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."') ");
答案 1 :(得分: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;