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. getCurrentLocation
is a method that returns the recently updated location.
- (void)showDirectionsToHere {
CLLocationCoordinate2D currentLocation = [self getCurrentLocation]; // LINE 1
NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
currentLocation.latitude,
currentLocation.longitude,
destCoordinate.latitude,
destCoordinate.longitude];
[[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 code in LINE1. I've just planned to do it that way.
My questions are:
- Is this good practice to calculate the Current Location, at the time the Maps app is called?
- Will
[self getCurrentLocation
] return the Current Location before openURL
gets called?
- Do 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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…