views:

665

answers:

2

Hi,

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?

+1  A: 

I think this answers your question : http://stackoverflow.com/questions/1652289/returning-mapkit-userlocation-coordinates/1652306#1652306

(uses the mapView.userLocation.location.coordinate.latitude and mapView.userLocation.location.coordinate.longitude properties )

and then inject those coordinates into the

-(void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated

of your MKMapView instance.

yonel
yeah or I can use the region.center.latitude = mapView.userLocation.location.coordinate.latitude; I think it will work right?
ludo
Hum, I'm not sure if it works, I would recommend you to create a local CLLocationCoordinate2D and inject it in the given selector. You get control over the animation parameter that could also make your app look nicer with an animation.
yonel
I don't really know how to use the selector you gave me but I will try, if you have any link to show me will be good too. thanks
ludo
something like this should be ok : CLLocationCoordinate2D myCoord = {mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude};[mapView setCenterCoordinate:myCoord animated:YES];
yonel
thanks I will try it today~
ludo
I still have a little problem, when I do NSLog(@"%i": mapView.userLocation.location.coordinate.latitude); I don't have a location number, I have something like thaT : 71502240
ludo
do @"%f" instead of %i
yonel
+2  A: 

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 startPdatingLocation];

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