Right now I am populating a map view with annotations, and also displaying the user\'s current location. With the viewForAnnotation method, it overrides all annotations with
Check out the documentation here:
http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html
As it states:
If the object in the annotation parameter is an instance of the
MKUserLocation
class, you can provide a custom view to denote the user’s location. To display the user’s location using the default system view, return nil.
So you can add a conditional to check for this:
if([annotation isKindOfClass: [MKUserLocation class]]) {
return nil;
}
Swift 5.0
Put a check at the top of the function to ignore the userLocation:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard annotation as? MKUserLocation != mapView.userLocation else { return }