ludo ludo - 2 months ago 19
Objective-C Question

Retrieve UserLocation Coordinate with MapKit

I"m using MapKit in my application and disaply the user location with


[mapview setShowUserLocation:YES];


I want to set the region.center.latitude and region.center.longitude with the coordinate of the userLocation, how to do it?

Answer

Here is my answer, I try something like that and its working:


//inside my ViewDidLOad
locManager = [[CLLocationManager alloc] init];
[locManager setDelegate:self];
[locManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locManager startUpdatingLocation];

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation  {
CLLocationCoordinate2D loc = [newLocation coordinate]; [maptView setCenterCoordiante:loc]; }
Comments