简体   繁体   中英

Move custom annotation to display user location

I have replaced the blue dot for user location in mapview with my custom annotation view, How can I make my custom annotation to follow user's location like the default blue dot does? When I replace the blue dot with my custom annotation or simply create MKAnnoationView , it just stops moving with the user. In viewForAnnotation delegate method of mapview , I am doing

pinView = [[MKAnnotationView alloc]
                  initWithAnnotation:annotation reuseIdentifier:defaultPinID];
        pinView.image = [UIImage imageNamed:@"newgreen2.png"];


        [mapView.userLocation setTitle:@"I am here"]; 

return pinView

This is showing a pin with newgreen2 image but it does not move, but if I return nil in this delegate method, blue dot appears by default which moves with user's location. Is there any trick to mimic this behavior of default blue dot for user location for my custom annotation view? I have noticed that viewForAnnotation is called only once and then blue dot automatically starts tracing the users location.

Is there any way by which I can tell my annotation view to follow the user's location?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM