如何找到矩形谷歌地图所覆盖的距离

时间:2014-08-13 06:29:19

标签: php google-maps distance

我使用绘图管理器在谷歌地图中绘制了一个矩形 如何找到以Km或英里为单位的矩形所覆盖的距离。

请帮帮我

1 个答案:

答案 0 :(得分:1)

Distance

中的两个Geopoints之间获取KM
function distanceGeoPoints ($lat1, $lng1, $lat2, $lng2) {

    $earthRadius = 3958.75;

    $dLat = deg2rad($lat2-$lat1);
    $dLng = deg2rad($lng2-$lng1);


    $a = sin($dLat/2) * sin($dLat/2) +
       cos(deg2rad($lat1)) * cos(deg2rad($lat2)) *
       sin($dLng/2) * sin($dLng/2);
    $c = 2 * atan2(sqrt($a), sqrt(1-$a));
    $dist = $earthRadius * $c;

    // from miles
    $meterConversion = 1609;
    $kilometerConversion = 1.609;
    $geopointDistance = $dist * $kilometerConversion;

    return $geopointDistance;
}

现在假设你有一个有四个点(A,B,C,D)的矩形

A __________________________ D    
 |                          |
 |                          |
 |                          |
 |__________________________|  
B                            C

所以你的距离将是

Total distance = 2 * ((distance between A and B) + (distance between A and D))