tags:

views:

6826

answers:

7

Hi all.

I know it's possible to start the iPhone maps application by calling openURL on a google maps URL with parameters saddr and daddr with location strings or LatLong (see ex. below), but I'm wondering if it's possible to make the start address be the "Current Location" maps bookmark so that I can use the maps app's location handling code. My Google search has been pretty fruitless.

ex:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%@&daddr=%@", myLatLong, latlong]]];

Except with something to invoke the current location bookmark in place of myLatLong.

Thanks!

+3  A: 

Because of sandboxing, you don't have access to the Map application's bookmarks.

Instead, use Core Location to determine the current location yourself. Then use that location (the lat and long) in the URL you build to open Maps.

August
I can't see how sandboxing would be relevant to asking Maps to use the Current Location. This is a nonsense answer.
grahamparks
+11  A: 

You need to use Core Location to get the current location, but with that lat/long pair, you can get Maps to route you from there, to a street address. Like so:


   CLLocationCoordinate2D currentLocation = [self getCurrentLocation];
   NSString* address = @"123 Main St., New York, NY, 10001";
   NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",
                    currentLocation.latitude, currentLocation.longitude,
                    [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
   [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
Nate
A: 

Question I have... is how you use this in the HTML?

Joshua
this is a totally legit question
larson4
A: 

i'm wondering the same. core location is fine for using the SDK, but if you wish to make a bookmarklet useful, you need to be able to access this info with html.

elvio
A: 

Can you explain it that we can use this in iPhone SDK.

Amol
A: 

You can do this now in html just from a url on your mobile device only. Here's an example. The cool thing is if you turn this into a qr code you have a way of someone getting directions to you from wherever they are just by scanning it on their phone.

mal