I'm Looking to change the appearance of the users location annotation. I understand this is now possible using MGLUserLocationAnnotationView
, however, I'm unsure how to implement this. Can anyone provide a simple example of how this is done?
Thanks
You are right. The MapBox API MGLUserLocationAnnotationView description is very short. The user location view customisation is available since MapBox iOS SDK 3.4.0. See also the feature comments on the MapBox GitHub
It is important to note: The MGLUserLocationAnnotationView is a subclass of the MGLAnnotationView. It means the MGLUserLocationAnnotationView acts just like a normal annotation view.
Here is an example how to customise the user location view. Create a new class (e.g. CustomUserLocationAnnotationView) and override a layoutSubviews() to add a custom code. In this example I use an UIImage UserLocationIcon.png to visualise the user position on the map.
In your UIViewController or whatever else (e.g. Service class) implement the MGLMapViewDelegate with at least two functions -mapViewDidFinishLoadingMap: and -mapView:viewForAnnotation:. See my comments inline:
The MapView -mapView:viewForAnnotation: delegate function is called for every annotation view instance including the user annotation view.
Optionally: To get your CustomUserLocationAnnotationView instance, you can use this function everywhere in your code: