1

In MKMapView I am having two type of map that is MKMapTypeStandard and MKMapTypeSatellite.
I want to replace user location pin to another(location.jpg) image.
The pin image is changing in MKMapTypeStandard (location.jpg) but in MKMapTypeSatellite(default image) pin image displayed as default map pin image.
how can i solve this problem in project?

Here is my code.

MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:nil];

     MKPinAnnotationView *customPinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
    //customPinView.image = [UIImage imageNamed:@"mappin4"];
    if (!pinView)
    {
        if (annotation == mapView.userLocation)
        {
            customPinView.image = [UIImage imageNamed:@"mappin4"];

        }
        else
        {

        }
        customPinView.animatesDrop = NO;
        customPinView.canShowCallout = NO;
        customPinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
       return customPinView;

    } else
    {
       pinView.annotation = annotation;
    }
Jay Bhalani
  • 4,142
  • 8
  • 37
  • 50
sathis
  • 19
  • 6

1 Answers1

0

Try like this ;

 - (void) changeMapType: (id)sender
    {
        if (mapView.mapType == MKMapTypeStandard)
            mapView.mapType = MKMapTypeSatellite;
        else
            mapView.mapType = MKMapTypeStandard;
    }

So by default if you use google maps, it is in the form of MKMapTypeStandard. you can change if you want by mapView.mapType = MKMapTypeSatellite;

you can also check following url ;

Why does a custom MKMapView annotation image disappear on touch?

Make sure you're using MKAnnotationView instead of MKPinAnnotationView everywhere in your viewForAnnotation method.

Community
  • 1
  • 1
Rohan
  • 2,939
  • 5
  • 36
  • 65