Search code examples
iosios7mkmapviewcllocation

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.


Solution

  • 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...
    
    
    }