How to display user location in mapkit?

I want to display a blue pulsating dot for the user's location. I'm doing it:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation    *)newLocation fromLocation:(CLLocation *)oldLocation{
//some other stuff here
[self.mapView setShowsUserLocation:YES];
}

But I end up getting

-[MKUserLocation establishment]: unrecognized selector sent to instance 0x125e90

Should I do it differently?

- EDIT -

I do this too, and I end up with an exception:

- (MKAnnotationView *) mapView:(MKMapView *)_mapView viewForAnnotation:(AddressNote *) annotation{

if(annotation.establishment != nil){
//do something}

Creation is a custom class that I use in AddressNote. When institution value matters, an exception is raised. If I do not set ShowsUserLocation, everything works fine, but of course I don't see the user's location.

+3
source share
3 answers

viewForAnnotation, , , . , , annoationView.


- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForNnotation: (id)  {   if ( == self.mapView.userLocation)       return nil;   //          ""  .

[EDIT] - :


- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForNnotation: (id)  {   if ([ isKindOfClass: [MKUserLocation class]])       return nil;   //          ""  .
+15

, , . mapView, .

mapView.showsUserLocation = YES;

, , .

+8

You are using the wrong delegate method. For mapview, you must use this delegate method to catch the user's location:

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
}
0
source

Source: https://habr.com/ru/post/1736905/


All Articles