2010-06-06 35 views
1

我正在尋找從uimapkit獲取經緯度的答案。有同樣的問題已被回答,但它沒有給出正確的座標。 http://yit.me/3ddp73如何在MapKit for iPad中獲取左上角和右下角的地圖緯度和經度?

它是我上面鏈接的代碼。

CLLocationCoordinate2D topLeft, bottomRight; 
topLeft = [mapView convertPoint:CGPointMake(0,0) toCoordinateFromView:mapView]; 
CGPoint pointBottomRight = CGPointMake(mapView.frame.size.width, mapView.frame.size.height); 
bottomRight = [mapView convertPoint:pointBottomRight toCoordinateFromView:mapView]; 


NSLog(@"topleft = %f", topLeft); 
NSLog(@"bottom right = %f", bottomRight); 

有什麼想法解決這個問題?

感謝

回答

0

原始溶液接近。視圖的座標系在左下角有原點。因此CGPoint(0,0)實際上是左下角,而不是頂部。另一個座標將是你的右上角。

2

地圖視圖具有region屬性。

MKCoordinateRegion region = mapView.region; 

區域包含中心和2D跨度,所以

CLLocationCoordinate2D topLeft = CLLocationCoordinate2DMake(
    region.center.latitude - region.span.latitudeDelta/2, 
    region.center.longitude - region.span.longitudeDelta/2, 
); 

+0

對不起,但它給了我「錯誤:無效初始值設定項」。 你能解釋爲什麼你使用CLLocationCoordinate2DMake不是簡單的CGPoint? 謝謝 – damniatx 2010-06-06 22:05:46

+0

@dam:您需要導入CoreLocation。 – kennytm 2010-06-06 22:22:07

+0

沒有解決錯誤。 -_- – damniatx 2010-06-06 22:30:32

相關問題