MKMapView zoom on current location

Hi,
I need in my application to locate the user. I'm using in my view a MKMapView. In IB, we can select the option "Show current location". It's works fine, but I would like to zoom on the current location.
How can I do?

Thank you.

Macbook Pro 13" 2009, Mac OS X (10.5.7)

Posted on Sep 9, 2009 1:42 AM

Reply
3 replies

Sep 9, 2009 2:34 AM in response to Dachmt

Yes, I used Google to find out how to do. I found many ways like your link. Let's explain my problem.

MKMapView showsUserLocation is at TRUE.
So, when the view loads, I have my map with an annotation "Current location" in blue, but I can almost see the world on the map. So I need to center and zoom on the current location in blue. But it didn't work for me, it zooms in the middle of the ocean, when I tried:

- (void)viewDidLoad {
MKCoordinateRegion region;
region.center.latitude = googleMap.userLocation.coordinate.latitude;
region.center.longitude = googleMap.userLocation.coordinate.longitude;
region.span.latitudeDelta = 0.0039;
region.span.longitudeDelta = 0.0034;
googleMap.region = region;
}

googleMap is my MKMapView object. I can't get my userLocation coordinates right. That's why I'm in the middle of the ocean.

Then, I tried in my view which is MKMapViewDelegate:

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
MKCoordinateRegion region;
region.center.latitude = mapView.userLocation.coordinate.latitude;
region.center.longitude = mapView.userLocation.coordinate.longitude;
region.span.latitudeDelta = 0.0039;
region.span.longitudeDelta = 0.0034;
mapView.region = region;
}

It didn't work either, I'm in still in the middle of the ocean, somewhere...
So how can I get the right user location that I can zoom on the right location?

Thank you.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

MKMapView zoom on current location

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.