I have set so that my MKMapView shows the current location. I also have a custom pin implemented for other pins. However, it turns out the current location shows as a custom pin, whereas I just wanted it to be a regular blue circle (like what google map has).
I have defined the following in my code:
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"];
if (pin == nil)
{
pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease];
}
else
{
pin.annotation = annotation;
}
[pin setImage:[UIImage imageNamed:@"TestPin.png"]];
pin.canShowCallout = YES;
pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return pin;
}
How can I prevent the current location to show up as a pin?
you need to implement this:-
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation:(id<MKAnnotation>) annotation
{
if (annotation == mapView.userLocation)
{
return nil;
}
else
{
MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"];
if (pin == nil)
{
pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease];
}
else
{
pin.annotation = annotation;
}
[pin setImage:[UIImage imageNamed:@"TestPin.png"]];
pin.canShowCallout = YES;
pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return pin;
}
}
For Swift:
if annotation is MKUserLocation {
return nil
}
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