问题
MKMapView show the pin on the center of the mapView, I want to position the pin location above the center. How do I do that?
Here is my code
- (void) location
{
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.1162;
span.longitudeDelta = 0.1160;
CLLocationCoordinate2D location;
location.latitude = 65.494806;
location.longitude = -23.577569;
region.span=span;
region.center=location;
PlaceMark *add_Annotation = [[[PlaceMark alloc] initWithCoordinate:location] autorelease];
[add_Annotation setTitle:@"myTitle"];
[add_Annotation setSubTitle:@"myAddress"];
[mapView addAnnotation:add_Annotation];
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
}
回答1:
If you want to keep the pin at those coordinates but center the map lower than the pin so that the pin is a little above the center, offset the center
of the region
by a fraction of the latitude span.
Instead of this:
region.center=location;
do this:
region.center = CLLocationCoordinate2DMake(
location.latitude - (span.latitudeDelta/5.0),
location.longitude);
Increase/decrease the divisor to reduce/increase the offset.
Also, the line [mapView regionThatFits:region];
is not needed--you can remove it.
First, setRegion
already does regionThatFits
itself and second, regionThatFits
returns a value but the code is not handling any return value.
来源:https://stackoverflow.com/questions/8171003/how-to-set-the-placemark-position-in-mkmapview