Lakshmi Reddy Lakshmi Reddy - 1 year ago 97
iOS Question

How to open a apple maps application with directions from my ios application

My aim is to open a map application from ios application with directions, I am able to open maps application but it is not showing directions, i have written the code as follows

NSString *mystr=[[NSString alloc] initWithFormat:@""];
NSURL *myurl=[[NSURL alloc] initWithString:mystr];
[[UIApplication sharedApplication] openURL:myurl];

Can any one please help me how figure out how to pass parameters to this url and any other?

Answer Source

If you mean taking the user to the maps application based on two points, then you can do it like this:

Create an NSURL that looks like this:

NSURL *URL = [NSURL URLWithString:@",%f&daddr=%f,%f"];

You plug in your starting address and destination (in lat. and long.) appropriately. Tell your application to open the URL

[[UIApplication sharedApplication] openURL:URL];

It should take you to the maps application automatically!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download