25

MKMapView に地域を設定し、マップの北東と南西の角に対応する座標を見つけたいと考えています。

This code works just fine to do that:
//Recenter and zoom map in on search location
MKCoordinateRegion region =  {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = mySearchLocation.searchLocation.coordinate;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[self.mapView setRegion:region animated:NO]; //When this is set to YES it seems to break the coordinate calculation because the map is in motion

//After the new search location has been added to the map, and the map zoomed, we need to update the search bounds
//First we need to calculate the corners of the map so we get the points
CGPoint nePoint = CGPointMake(self.mapView.bounds.origin.x + mapView.bounds.size.width, mapView.bounds.origin.y);
CGPoint swPoint = CGPointMake((self.mapView.bounds.origin.x), (mapView.bounds.origin.y + mapView.bounds.size.height));

//Then transform those point into lat,lng values
CLLocationCoordinate2D neCoord;
neCoord = [mapView convertPoint:nePoint toCoordinateFromView:mapView];
CLLocation *neLocation = [[CLLocation alloc] initWithLatitude:neCoord.latitude longitude:neCoord.longitude];

CLLocationCoordinate2D swCoord;
swCoord = [mapView convertPoint:swPoint toCoordinateFromView:mapView];
CLLocation *swLocation = [[CLLocation alloc] initWithLatitude:swCoord.latitude longitude:swCoord.longitude];

問題は、マップのズームをアニメーション化することです。ただし、setRegion:animated を YES に設定すると、ズームアウトしたとき (つまり、アニメーションが完了する前) にマップから座標を取得することになります。アニメーションが完了したという信号を取得する方法はありますか?

4

2 に答える 2

23

mapkit を使用したことはありませんが、MKMapViewDelegatemapView:regionDidChangeAnimated:には、探しているように見えるメソッドがあります。

ユーザーがマップを移動したときなど、変更があるたびmapView:regionDidChangeAnimated:に が呼び出されることに注意してください。

于 2010-01-17T19:38:56.217 に答える