Question

I need to open Maps from my app with the routes already traced. The start point is the user location (already have it), and the end point is a establishment that I have latitude and longitude.

Looking through Apple documentation on MapLinks, I found out that it's possible to pass the addresses as string, but I didn't see anything about lat+long.

Has anyone done this before? Is it possible?

Was it helpful?

Solution

It is very possible. Instead of passing an address, simply pass the lat and lon values in a string, separated by a comma. For example, if you want to open the maps app with the current user's lat/lon location and directions to the Empire State building, you could put in

CLLocationCoordinate2D empireStateLocation = CLLocationCoordinate2DMake(40.7484, -73.9857);

NSString *queryString = [NSString stringWithFormat:@"http://maps.apple.com/?saddr=%f,%f&daddr=%f,%f", mapView.userLocation.coordinate.latitude, mapView.userLocation.coordinate.longitude, empireStateLocation.latitude, empireStateLocation.longitude];

NSURL *url = [NSURL URLWithString:queryString];
[[UIApplication sharedApplication] openURL:url];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top