Open Maps app from Code : Where to find the "Current Location"?
- by Simon
I am opening Maps app to show directions from user's Current Location to a destination coordinate, from my code. I am using the following code to open the Maps app. I am calling this code when a button is pressed.
- (void)showDirectionsToHere {
CLLocationCoordinate2D currentLocation = [self getCurrentLocation]; // LINE 1
NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", destCoordinate.latitude + 0.1, destCoordinate.longitude, destCoordinate.latitude, destCoordinate.longitude];//8.3, 12.1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
Here [self getCurrentLocation] in LINE 1 uses CLLocationManager to determine the Current Location and returns the value.
Note: I have not yet implemented the LINE1. I've just planned to do in that way.
My question is,
Is this a good practice to calculate the Current Location, at the time the Maps app is called?
[self getCurrentLocation] will retrun the Current Location before openURL gets called?
I have to determine the Current Location well before opening the Maps app?
I am little bit confused about these things. Kindly guide me. Thanks.