How to show the user's default location and the individual type of annotation in the map set?

I use a set of maps and show an individual view of annotations. One is carImage and the other is userImage (as the current location of the user). Now I want to show the current user location by default, which is provided by map kit.but is unable to show it. How to show the blue circle + my car in the map set?

+3
source share
1 answer

To show the user's location, set the map property to the following property:

mapView.showsUserLocation = YES;

,

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{
// check for nil annotation, dequeue / reuse annotation
// to avoid over riding the user location default image ( blue dot )

if ( mapView.UserLocation == annotation ) {

return nil; // display default image

}

MKAnnotationView* pin = (MKAnnotationView*)
[mapView dequeueReusableAnnotationViewWithIdentifier: PIN_RECYCLE_ID];

if ( pin == nil ) {

pin = [(MKAnnotationView*) [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: PIN_RECYCLE_ID] autorelease] ;

pin.canShowCallout = YES;

}
else {

[pin setAnnotation: annotation];
}

pin.image = [UIImage imageNamed:@"car-image.png"];

return pin;
}
+7

Source: https://habr.com/ru/post/1720780/


All Articles