本文介绍了如何在MapKit中获取地图的左上角和右下角经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在MapKit中获取地图的左上角和右下角经度?
我使用此代码,但它无法正常工作。我该如何解决?
How to get left-top and right-bottom latitude and longitude of map in MapKit?I use this code, but it doesn't work properly. How should I fix it?
MKCoordinateRegion region = [map region];
double topL,topG,bottomL,bottomG;
//if latitude=55 and latitudeDelta=126 topL is 118 and it will be not at top, it will be at buttom of screen
topL = region.center.latitude + region.span.latitudeDelta/2;
topG = region.center.longitude - region.span.longitudeDelta/2;
CLLocationCoordinate2D lt;
lt.latitude=topL;
lt.longitude=topG;
annotation = [Annotation new];
annotation.coordinate = lt;
annotation.title = @"Left";
[map addAnnotation:annotation];
[annotation release];
//if latitude=55 and latitudeDelta=126 bottomL is -7.23 and it will be not at bottom, it will be at above bottom of screen
bottomL = region.center.latitude - region.span.latitudeDelta/2;
bottomG = region.center.longitude + region.span.longitudeDelta/2;
CLLocationCoordinate2D rb;
rb.latitude=bottomL;
rb.longitude=bottomG;
annotation = [Annotation new];
annotation.coordinate = rb;
annotation.title = @"Right";
[map addAnnotation:annotation];
[annotation release];
推荐答案
获取这些坐标有一种更简单的方法。 ..使用您的观点,并转换:
There is a much easier approach to getting those coordinates... Use the points of your view, and convert:
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];
这篇关于如何在MapKit中获取地图的左上角和右下角经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!