Iphone 如何在MKOBLADE中间定位UIMAPVIEW

Iphone 如何在MKOBLADE中间定位UIMAPVIEW,iphone,ios,mkoverlay,mkmapview,Iphone,Ios,Mkoverlay,Mkmapview,我使用以下代码(基于Apple WWDC 2010 TileMap示例)加载带有MKOverlay图像的UIMapView(这可能在viewDidLoad方法中): 接下来,我要将UIMapView地图放在这个覆盖图的中心。目前,我正在对纬度和经度进行硬编码,如下所示: double myLatitude = ...; double myLongitude = ...; CLLocation *location = [[CLLocation alloc] initWithLatitude:myL

我使用以下代码(基于Apple WWDC 2010 TileMap示例)加载带有MKOverlay图像的UIMapView(这可能在viewDidLoad方法中):

接下来,我要将UIMapView地图放在这个覆盖图的中心。目前,我正在对纬度和经度进行硬编码,如下所示:

double myLatitude = ...;
double myLongitude = ...;
CLLocation *location = [[CLLocation alloc] initWithLatitude:myLatitude longitude:myLongitude];
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, 4000, 4000);
MKCoordinateRegion adjustedRegion = [map regionThatFits:viewRegion];
[map setRegion:adjustedRegion animated:YES];
double x, y;

x = MKMapRectGetMidX([overlay boundingMapRect]);
y = MKMapRectGetMidY([overlay boundingMapRect]);
CLLocationCoordinate2D coord = MKCoordinateForMapPoint(MKMapPointMake(x, y));

MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(coord, 4000, 4000);
MKCoordinateRegion adjustedRegion = [map regionThatFits:viewRegion];
[map setRegion:adjustedRegion animated:YES];
这个很好用。我已尝试按如下方式计算叠加的中心:

double myLatitude = ...;
double myLongitude = ...;
CLLocation *location = [[CLLocation alloc] initWithLatitude:myLatitude longitude:myLongitude];
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, 4000, 4000);
MKCoordinateRegion adjustedRegion = [map regionThatFits:viewRegion];
[map setRegion:adjustedRegion animated:YES];
double x, y;

x = MKMapRectGetMidX([overlay boundingMapRect]);
y = MKMapRectGetMidY([overlay boundingMapRect]);
CLLocationCoordinate2D coord = MKCoordinateForMapPoint(MKMapPointMake(x, y));

MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(coord, 4000, 4000);
MKCoordinateRegion adjustedRegion = [map regionThatFits:viewRegion];
[map setRegion:adjustedRegion animated:YES];
但这是行不通的。mkCoordinateFormAppPoint返回覆盖外的纬度/经度。我不明白为什么

有人能提出解决办法吗


提前感谢…

您是否修改了示例代码中的boundingMapRect计算?尽管不需要调整的区域计算(setRegion将进行区域拟合),但居中代码看起来正常。我得到37.718590,-122.343750。你得到什么坐标?这也是我得到的…当坐标在覆盖层内时,它不在中心。