2010-06-06 34 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

相关问题