So, I've created a CLLocationManager, called it to start updating, set mapView.showsUserLocation to YES, and returned nil for the userLocation annotation. Here are some snippets from my code in my UIMapViewController:
- (void)viewDidLoad
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D userCoordinate = locationManager.location.coordinate;
[map setCenterCoordinate:userCoordinate animated:YES];
[map setShowsUserLocation:YES];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *mapIconView = (MKAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:@"mapIconView"];
// Don't mess with the user location annotation
if (annotation == mapView.userLocation)
return nil;
// etc.
}
This all seems pretty straightforward. Everything works fine--the map zooms to my location as it should, and I've confirmed that all the methods are called as expected--but no blue dot. Can't get the blue dot for the life of me, no matter where or how many times I say
mapView.setUserLocation = YES;
What am I missing here?
It's mapView.showUserLocation = YES;
You seem to have used the wrong statement 'set' instead of 'show'.
And FYI, you don't have to mess with the location manager just to get the userlocation. Corelocation automatically gets fired when you set
mapview.showUserLoction = YES
and load the map.Hope it helps :)
Make sure that you are not removing all annotations from the map anywhere:
e.g. [mapView removeAnnotations:mapView.annotations]
When I do this, rather than checking
annotation
like you have, I do something along the lines of:I had this same problem where the blue dot wouldn't appear. Turns out it was appearing, just not where I thought it was.
Similarly to my issue, your code looks like it's both processing location updates and asking the MKMapView to track the user location. Note that in the simulator, these are two different locations! When the MKMapView is tracking the user location in the simulator, it gives you the location of Apple in Cupertino, CA, regardless of your "actual" location.
Using this code and letting the MKMapView track the location for your delegate instead of tracking the location yourself can reveal the blue dot:
You'll probably want to zoom in a bit. I used the handy code from this blog entry to do that: Set the Zoom Level of an MKMapView
If you are using the iOS simulator, then you can't see the blue dot. I had the exact same problem and when I started to try my software with the real hardware the blue dot showed up!