Open Maps app from Code : Where to find the "Current Location"?

Posted by Simon on Stack Overflow See other posts from Stack Overflow or by Simon
Published on 2011-01-04T05:42:44Z Indexed on 2011/01/04 5:53 UTC
Read the original article Hit count: 204

Filed under:

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,

  1. Is this a good practice to calculate the Current Location, at the time the Maps app is called?
  2. [self getCurrentLocation] will retrun the Current Location before openURL gets called?
  3. 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.

© Stack Overflow or respective owner

Related posts about iphone