Reputation: 1451
I have a mapView
in which I want to show user's current location. However, I don't want to centre the mapView
to that location (it is centred to other location). So, for that reason, I don't get coordinates for the user's location to set the region. I just call showsUserLocation
and set it to true. Everything works fine, except the fact that this makes my mapView
show user's current location just as a pin. I would like it to be in a form of a default blue dot.
Related to the problem above, I have two questions: 1) Why does it show user's current location as a pin? 2) How can I make it show user's current location as a blue dot?
If you know the answers to these questions (or only to one of them) I would appreciate your help.
Upvotes: 2
Views: 868
Reputation: 3545
We need to check the type of annotation, if it is a user location do not want to return a pin:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
[... code for the other annotations ... ]
}
Now you will see your location as a classic blue dot.
Upvotes: 0
Reputation: 535890
Everything depends on your implementation of the map view delegate's mapView(_:viewFor:)
. You are probably returning a pin annotation.
You can distinguish the annotation provided by the map view as the user's location by checking its class, which will be MKUserLocation. If you want the default blue dot, return nil
for that class.
Upvotes: 2