0

我需要使用谷歌地图 api 来计算两个地方之间的 x 和 y 距离,因为谷歌地图使用墨卡托投影。我不需要两个地方之间的距离,而是delta x(沿经线)和delta y(沿平行线)。如果有两个坐标为 (x1,y1) 和 (x2,y2) 的地方有 lat-longs (lat1,long1) 和 (lat2, long2),我想计算 x2-x1 和 y2-y1,总和这两个的平方当然给出了两个地方之间的位移平方。google maps api可以直接返回笛卡尔坐标吗?

4

3 回答 3

0

试试这个haversine公式来测量PHP中两个坐标之间的距离

function haversineGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000)
{
  // convert from degrees to radians
  $latFrom = deg2rad($latitudeFrom);
  $lonFrom = deg2rad($longitudeFrom);
  $latTo = deg2rad($latitudeTo);
  $lonTo = deg2rad($longitudeTo);

  $latDelta = $latTo - $latFrom;
  $lonDelta = $lonTo - $lonFrom;

  $angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) +
    cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));
  return $angle * $earthRadius;
}
于 2013-02-18T16:34:10.943 回答
0

有几种方法GMSProjection可以在坐标(经纬度)和点之间进行转换。

/** Maps an Earth coordinate to a content coordinate. */
- (CGPoint)pointForCoordinate:(CLLocationCoordinate2D)coordinate;

/** Maps a content coordinate to an Earth coordinate. */
- (CLLocationCoordinate2D)coordinateForPoint:(CGPoint)point;

我认为没有获得点之间距离的方法,但您应该能够使用标准公式。这是一个

CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
{
    CGFloat dx = point2.x - point1.x;
    CGFloat dy = point2.y - point1.y;
    return sqrt(dx*dx + dy*dy );
};
于 2013-02-15T14:56:32.740 回答
0

在 WGS84 度中给出两点:

(lon1, lat1),
(lon2, lat2)

要获得三角洲纬度:

dLat = lat2- lat1;

longitide 也一样

dLon = lon2 - lon1;

delta 结果现在以度为单位。

如果您希望结果以米为单位,则必须采用 x,y 中的投影坐标

deltaXMeter = x2 - x1;
deltayMeter = y2 - y1;

当 x 和 y 是笛卡尔米坐标系中的坐标时。

于 2013-02-15T16:37:00.653 回答