I would like to find out userlocation coordinate while my app is loading. I have implemented following code but it returns 0.000
mapView.showsUserLocation=YES;
CLLocationCoordinate2D annotationCoordinate;
annotationCoordinate.latitude=mapView.userLocation.location.coordinate.latitude;
NSLog(@"%f",annotationCoordinate.latitude);
I could not able to figure out. Any help?
First of all you should take into account that it takes time to retrieve the user location. Moreover the user can disable the location service for your application or even the location service can be unavailable during the connectivity conditions. So you’d better to rethink your application starting procedures.
When you make up you decision take a look at
mapView:didUpdateUserLocation:method ofMKMapViewDelegateprotocol. After this method fires out the location can be available via theuserLocationproperty of theMKMapView.UPDATE
In case you want to open map view with the user location already checked, you may consider using
CLLocationManagerandCLLocationManagerDelegate. This way you can check if the location service is available and open map view after the methodlocationManager:didUpdateToLocation:fromLocation:fires up.For the complete info take a look at Getting the User’s Location programing guide