Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show User Location in MapView

I'm writing an App with a mapView showing some Annotations.

Now I want to show the User's current location in the mapView. I get the current Location using this code:

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

I get the details of 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 don't get the location into the mapView as this blue pulsing dot.

Please give some hints.

like image 586
Christian Seiler Avatar asked Oct 14 '13 10:10

Christian Seiler


3 Answers

In xCode 9 you could do it with storyboard file

enter image description here

like image 165
Arek Avatar answered Oct 17 '22 01:10

Arek


You can enable the userlocation by this:

mapView.showsUserLocation = YES;

if you want to center on this location:

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

if you are using:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{

if ([annotation isKindOfClass:[MKUserLocation class]]) {
    return nil;
}

// etc...


}
like image 30
incmiko Avatar answered Oct 17 '22 01:10

incmiko


In iOS10 I could not get the blue dot for the user location to show until adding the key NSLocationWhenInUseUsageDescription to my Info.plist, with a string description of how location info would be used in the app.

like image 3
saswanb Avatar answered Oct 17 '22 00:10

saswanb