以度/公里为单位获取Google静态地图的尺寸

时间:2013-03-18 17:12:25

标签: google-maps latitude-longitude google-static-maps

我想知道是否有任何方法可以获得谷歌静态地图图像的尺寸(以度或公里为单位),给定缩放级别和地图大小(以像素为单位)。

我已经看到了一个公式来获得经度:

(widthInPixels/256)*(360/pow(2,zoomLevel));

这非常准确。但是,km和度之间的比例会根据你与极点或赤道的距离而变化,所以这个公式不起作用(即使我用360代替180)

有没有人得到一个公式或任何提示?

1 个答案:

答案 0 :(得分:1)

您可以使用MKMetersBetweenMapPoints查找以km为单位的尺寸。

//Let's say region is represents the piece of map
    MKMapPoint pWest = MKMapPointForCoordinate( CLLocationCoordinate2DMake(region.center.latitude, region.center.longitude-region.span.longitudeDelta/2.0));
    MKMapPoint pEast = MKMapPointForCoordinate( CLLocationCoordinate2DMake(region.center.latitude, region.center.longitude+region.span.longitudeDelta/2.0));
    CLLocationDistance distW = MKMetersBetweenMapPoints(pWest, pEast)/1000.0;//map width in km
    MKMapPoint pNorth = MKMapPointForCoordinate( CLLocationCoordinate2DMake(region.center.latitude+region.span.latitudeDelta/2.0, region.center.longitude));
    MKMapPoint pSouth = MKMapPointForCoordinate( CLLocationCoordinate2DMake(region.center.latitude-region.span.latitudeDelta/2.0, region.center.longitude));
    CLLocationDistance distH = MKMetersBetweenMapPoints(pNorth, pSouth)/1000.0;;//map height in km