Returning Mapkit Userlocation Coordinates
Question
whenever I try to return the lat/long coordinates for my current location, my application crashes with no explanation of the error...
NSLog(@"%@", mapView.userLocation.location.coordinate);
I am waiting until the phone finds the location as well...
Solution
mapView.userLocation.location.coordinate
is a struct while the %@
format specifier expects an object. This will work:
NSLog(@"%f, %f", mapView.userLocation.location.coordinate.latitude,
mapView.userLocation.location.coordinate.longitude);
OTHER TIPS
For some reason, this didn't work for me. It's taking me to the coordinates (0.0000, 0.0000). Below is my code if you have a chance to check it out. Thanks for the help!
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
mapView.showsUserLocation=TRUE;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
CLLocationCoordinate2D myCoord = {mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude};
[mapView setCenterCoordinate:myCoord animated:YES];
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow