keep on you
keep on you

Reputation: 310

How can i use Maps directions app?

I have an app that display locations on the MapView, and i want to get the direction of a specific location from my current location using the Directions APP on the iPhone. how can i do that?

Upvotes: 0

Views: 133

Answers (3)

Ashley Mills
Ashley Mills

Reputation: 53082

From your question, I assume you want to get directions using the Maps app.

To do this you'll need to code something like:

NSString *mapsUrl = 
       [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",
        self.mapView.userLocation.location.coordinate.latitude,
        self.mapView.userLocation.location.coordinate.longitude,
        <destination address>];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: [mapsUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]];

where saddr is the start address (or lat, lon pair in this case) and daddr is the destination address.

Upvotes: 1

Michael Frederick
Michael Frederick

Reputation: 16714

I have done that before. It is basically more trouble than it's worth because you have to implement the directions yourself and every time the Map app gets new features added then the direction system in your app will become outdated. What you really want to do is create a link for the directions to open in the Map app. Owners always make the argument that they don't want the user to have to leave the app, but ultimately you want to provide the best utilities for the user and unfortunately linking to the map app is the way to go here.

You can link to the map app like this:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://maps.google.com/whateveryoururlis"];

Upvotes: 0

Krishna K
Krishna K

Reputation: 708

This is a pretty old post from Jeff: http://iphonedevelopment.blogspot.com/2009/02/mapping-directions-from-your-app.html .

Upvotes: 1

Related Questions