質問

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.

役に立ちましたか?

解決

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


}

他のヒント

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.

In xCode 9 you could do it with storyboard file

enter image description here

I ran into the same because I removed my type check code for AnnotationViews because I didn't need that anymore. 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()
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top