shajem
shajem

Reputation: 2121

How to show User current Location - GPS

I followed the following tutorial to embed Maps to my application.

Later on I have added a button, and when the user clicks on it, I will show the user their current location; here's my code:

-(void)showUserLocation {
self.mapView.showsUserLocation=YES;
}

But, when the map is pointed to Russia, and my user location is in London how can I move the map to my userlocation ?

In detail: When I click the button Show User current location, it draws the blue dot on the map. But it doesn't take me to that point. If the map is pointed to Russia, and my user location is in London, how can I move the map to point to my user location?

Upvotes: 1

Views: 289

Answers (1)

fscheidl
fscheidl

Reputation: 2301

Take a look at this MKMapView method: setCenterCoordinate:animated:

MKUserLocation *location = self.mapView.userLocation;
[self.mapView setCenterCoordinate: CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longutde) animated:YES];

This should be preferably be implemented using this MKMapViewDelegate method: mapView:didUpdateUserLocation

Upvotes: 3

Related Questions