2013-03-18 18 views
0

我想知道是否有任何獲取谷歌靜態地圖圖像的尺寸(以度或公里爲單位)的方式,給定縮放級別和地圖尺寸(以像素爲單位) 。以度/公里爲單位獲取Google靜態地圖的尺寸​​

我看到一個公式來獲取經度度:

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

這是相當準確的。然而,公里和度之間的比例取決於你與兩極或赤道的距離有多大,所以這個公式不起作用(即使我用360代替180)

有沒有人有公式或任何提示爲了這?

回答

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 
相關問題