How can i use Maps directions app?

139 views Asked by At

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?

3

There are 3 answers

0
Krishna K On
0
Michael Frederick On

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"];

0
Ashley Mills On

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.