Show user location in MapView

I am writing an application with mapView showing some annotations.

Now I want to show the current location of the user in mapView. I get the current location with this code:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)location 

I get information about the current location in the log

 2013-10-14 12:03:34.291 AppName[13200:a0b] ( "<+7.35000000,+47.32000000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 10/14/13, 12:03:34 PM Central European Summer Time") 

Now I do not get the location in mapView as this blue pulsating dot.

Please give some advice.

+9
ios ios7 cllocation mkmapview
source share
4 answers

You can enable userlocation as follows:

 mapView.showsUserLocation = YES; 

if you want to focus on this place:

 [mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES]; 

if you use:

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { if ([annotation isKindOfClass:[MKUserLocation class]]) { return nil; } // etc... } 
+27
source share

In iOS10, I could not get the blue dot for the user's location until the NSLocationWhenInUseUsageDescription key was added to my Info.plist, with a string description of how the location information will be used in the application.

+3
source share

In xcode 9 you can do this with a storyboard file

enter image description here

0
source share

I came across the same because I deleted my type checking code for AnnotationViews because I no longer need it. So I made a Swift version of @incmiko's answer.

 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { guard !annotation.isKind(of: MKUserLocation.self) else { return nil } //create annotation view return MKAnnotationView() } 
0
source share

All Articles