简体   繁体   中英

Mapbox custom user location image

I'm using Mapbox 2.1.2 where I need to set a custom image for the user location annotation. This is not a problem to implement both in MapKit or GoogleMaps but how do I deal with this using Mapbox?

If this is not possible, how can I track the user's location? I've already tried to add MGLPointAnnotation objects on location update. But then I have to have a cache of annotations and clear it on adding a new, most recent one which also leads to a "flash" ugly effect.

Background on customizing the user location annotation: https://github.com/mapbox/mapbox-gl-native/issues/2272

The best way to do this right now is to follow the guidance there, which is to customize the MGLUserLocationAnnotation class in the source code (the SDK is open source).

As of Mapbox iOS SDK v3.4.0, you can provide your own user location annotation view that contains a UIImageView. In your MGLMapViewDelegate, implement the -mapView:viewForAnnotation: method to check whether the annotation is equal to the MGLMapView's userLocation ; if so, return a new MGLUserLocationAnnotationView that contains a UIImageView. There's a work-in-progress example of customizing the user dot in this pull request .

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