Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show default user location and a customized annonation view in map kit?

I am using map kit and showing customized annotation view. One is carImage and the another one is userImage(as current location of user). Now I want to show current user location default which is provided by map kit.but unable to show it. How do I show blue circle+my car in map kit?

like image 869
Rahul Vyas Avatar asked Mar 01 '23 03:03

Rahul Vyas


1 Answers

To show the user location, set the following property to true on the map view object

mapView.showsUserLocation = YES;

To display a custom annotation, set image property on the map view annotation

 - (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;
}
like image 75
RocketMan Avatar answered Apr 08 '23 17:04

RocketMan