MKMapView not centered on pin
I have an mkmapview that i'm currently adding pins to, but for some reason when I call [mapView setRegion:[detailItem coordinateRegion] animated:YES];
the pin is off-centered (toward the right side of the screen) on the map. Here is the code for [deailItem coordinateRegion]
:
- (MKCoordinateRegion)coordinateRegion {
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center = self.coordinate;
region.span.longitudeDelta = 0.0075f;
region.span.latitudeDelta = 0.0075f;
return (region);
}
I'm setting the coordinateRegion's center to the object's x,y coordinate, so why is it off-center o开发者_StackOverflow中文版n the map? I feel like there's something I'm missing here...
::Val::
What are your bounds for MKMapView
? You shouldn't have to do anything after you've selected the annotation ([mapView selectAnnotation:annotation animated:YES];
).
It could be that your frame for MKMapView
is bigger than your actual viewing area. The map is centered, but the view is not.
The documentation discusses this the vert vs. horizontal spans are not identical because one degree of latitude does not equal one degree of longitude. This effect will be more pronounced by the poles. Try using setCenter after you've applied the region. See the docs for further discussion of span.
精彩评论