I have an application that uses iphone map kit. It shows set of standard pins. Now I switch to custom images for pins (using MKMapViewDelegate)
The problem is that custom pins are not centered right - custom pin pointing to a location near original.
The question is how iphone works with custom pin. For example: let's have a image for pin 50x50 pixels. And we have global coordinate (long, lat): XY
How will iphone center image?
thank you
You can mark places in the Maps app with pins to help you find those places later. Tip: To quickly mark your location so you can find your way back later, touch and hold the Maps icon on the Home Screen, then choose Mark My Location. See Perform quick actions on iPhone.
It's the same accuracy as the GPS accuracy of the device. If the GPS on the iPhone can't obtain a good signal, it may use Wi-Fi triangulation which will reduce the accuracy.
Buried in your iOS location settings is a feature called "Frequent Locations." This is plotting the places you often go, including complete addresses and even a map. If something about that feels not great to you, here's how to find and disable it.
You can rearrange the pinned conversations easily — simply drag a pinned conversation where you want it, then release. You'll see the other pins move around and out of the way.
If you assign your custom image to the image property. When the annotation is displayed, the image is displayed centered over the target map coordinate. If you do not want the image to be centered on the map coordinate, you can use the centerOffset property to move the center point horizontally and vertically in any direction.
So the custom image is displayed in the center of your targeted coordinates only.
MKAnnotationView* aView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"MyCustomAnnotation"] autorelease];
aView.image = [UIImage imageNamed:@"myimage.png"];
aView.centerOffset = CGPointMake(10, -20);
Source: apple class reference for MKMapView
The solution is to set center offset in the delegate of the mapView, and not in the annotation view it self:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString* const kPinIdentifier = @"pinidentifier";
PinAnnotationView* customPinView = [[[PinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:kPinIdentifier] autorelease];
customPinView.canShowCallout = NO;
// Here !!
customPinView.centerOffset = CGPointMake(0, -21.5f);
return customPinView;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With