views:

322

answers:

1

I'd like to center a map (mapkit) against the user's location. I do the following in the simulator but only get a blue map with no content. What steps should I be taking?

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;

CLLocationCoordinate2D location;
location.latitude = mapView.userLocation.location.coordinate.latitude;
location.longitude = mapView.userLocation.location.coordinate.longitude;

region.span=span;
region.center=location;
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];

The long/lat values from the above are:

location.latitude = 1.0256307104653269e-305
location.longitude = 1.2742349910917941e-313

--- EDIT ---
I found the answer to my follow up comment here: http://stackoverflow.com/questions/1764019/mapkit-userlocation-found-event. Used with the answer below, that provides the solution.

+1  A: 

A blue map with no content usually means that you're somewhere in the ocean. Zoom out and check your coordinates, you're most likely off the coast of Africa at latitude 0.0 and longitude 0.0. Have you checked to see what values are in your latitude and longitude?

You could also try using -setCenterCoordinate: animated: with the userLocation center.

nevan
I've updated the question to reflect some answers to your questions. I'm also doing this [self.mapView setCenterCoordinate:self.mapView.userLocation.location.coordinate] but I'm still out in the Atlantic Ocean.
4thSpace