2011-03-14 31 views
1

我在MKMapView上繪製了3個MKPolyLine。如何放大顯示這三條路線的最大可能? 我知道我必須使用setRegion方法。然而我很困惑如何計算MKCoordinateRegion和MKCoordinateSpan。 有人可以幫我嗎?謝謝使用MKPolyLine在MKMapView上縮放級別和註解

另外一個問題是我怎樣才能在MKPolyLine中間顯示一個註釋(即:路線中間)?

回答

1

我會做到以下幾點:

  • 查找所有的折線的最大和最小緯度和經度值。然後做:

CLLocationDegrees deltaLat = maxLat-minLat; 

CLLocationDegrees deltaLong = maxLong-minLong; 

CLLocationCoordinate2D centerCoord = CLLocationCoordinate2DMake(deltaLat/2, deltaLong/2); 

MKCoordinateSpan span = MKCoordinateSpanMake(deltaLat, deltaLong); 

MKCoordinateRegion region = MKCoordinateRegionMake(centerCoord, span); 

[mapView setRegion : region animated : YES]; 
+0

怎麼樣把標註在航線的中間? – aherlambang 2011-03-14 21:52:31

+0

爲了達到這個目的,您首先需要計算總路線長度,除以2(以獲得中途距離),並在您的折線上找到距離起點中點一半的點。 看看[CoreLocationUtils](https://github.com/100grams/CoreLocationUtils)計算距離等 – 100grams 2011-05-18 13:49:52

+0

計算總路線長度是相當基本的東西,但找到沿着MKPolyline的中間點(可能只有由起點和終點組成)似乎對我來說很難。 CoreLocationUtils也沒有幫助。 – samvermette 2012-11-10 01:23:40