Reputation:
i can open the apple maps application from my app to calculate a route from the current location to my placemark and it works fine.
but now i have a list of several placemarks in a given order and would like to send them to the maps application to be used as targets in between along a route from first to last placemark. is this possible?
i could as an alternative start google maps on safari which allows to set multiple targets in the url: https://maps.google.com/maps?saddr=first&daddr=second&daddr=third+to:final&hl=en
Upvotes: 0
Views: 337
Reputation: 325
i used the code below and it worked fine for several months but now the new online version of google maps doesn't support multiple targets requested like this anymore.
therefore you need to adjust your url like this: https://www.google.com/maps/dir/longitude,latitude/longitude,latitude
here you can find some more information about the url search: http://gearside.com/easily-link-to-locations-and-directions-using-the-new-google-maps/
Upvotes: 1
Reputation:
my current solution is opening google maps on safari with the link, where i add +to: targets in between:
for (int i == 0; int i < route.count; i++) {
if (i == 0) {
NSString *start = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f", latitude, longitude];
locationString = start;
}
if (i != 0 && i != route.count - 1) {
NSString *between = [NSString stringWithFormat:@"+to:%f,%f", latitude, longitude];
locationString = [locationString stringByAppendingString:between];
}
if (i == route.count - 1) {
NSString *end = [NSString stringWithFormat:@"&daddr=%f,%f", latitude, longitude];
NSString *type = @"&dirflg=w";
locationString = [locationString stringByAppendingString:end];
locationString = [locationString stringByAppendingString:type];
}
}
NSURL *url = [NSURL URLWithString:locationString];
[[UIApplication sharedApplication] openURL:url];
this works fine if I'm using the iOS 5 or 6 sSimulator which opens the link in Safari on the mobile version of maps.google.com
but when i run it on an iOS 5 device and probably on an iOS6 device with installed Google Maps the link starts in Google Maps and there the route is drawn wrong (especially with many targets) and the targets in between have no annotations...
anybody got an idea how to force a link beeing opened in Safari?
Upvotes: 0