2
votes

MapView is showing my current location but no red pin (or blue circle) appears. Location services are enabled on this device. However, the red pin is shown running on simulator the same code. I already set required property:

self.mapView.showsUserLocation = YES;

I'm using custom pins, however, "mapView:viewForAnnotation:" is called only for each custom annotation, so it looks like this method is not called for current location and that's why it's not showing red pin. However, very strange why the same code runs correctly on simulator.

UPDATE Just created empty single view project with mapView. Did add self.mapView.showsUserLocation = YES but no current location is shown on device. BUT a blue circle is shown in simulator. I'm using iOS 6.1.2 on my iPhone4.

3

3 Answers

3
votes

mapView:viewForAnnotation: is called for the current location.

From the docs:

If the object in the annotation parameter is an instance of the MKUserLocation class, you can provide a custom view to denote the user’s location. To display the user’s location using the default system view, return nil.

In your implementation of that delegate method, check the class of the annotation that is passed in and proceed accordingly (either return nil to use the blue dot or return a custom view).

If it's not getting called, something else is afoot.

1
votes

In mapView:viewForAnnotation method add before other code

if([a isKindOfClass:[MKUserLocation class]])
   return;
0
votes

Maybe you return an empty pin every time, so even when you should be returning the annotation for the user location, you return this empty pin. Try this in your viewForAnnotation delegate:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation
{
    // When returning nil, it should show the default blue dot
    if(annotation == mapView.userLocation) return nil;

    // Dequeue the annotations for actual points, do whatever, and return the correct pins
}

EDIT: If your delegate method is not called on the device, my guess is probably there is a memory leak in there somewhere. In simulator, the memory is that of the computer you are using it on, but on the device, this is more restricted.