how to launch default driving directions or map app from another native app

I want to press a button in my native app which will be both android and iphone, and have it launch the default maps/directions app or at least ask the user which app to choose. Is this possible in both android and IOS? If so, could anybody provide a good link? Is it also possible to provide starting and destination parameters? Thanks a bunch.
LVL 9
BobHavertyComhAsked:
Who is Participating?
 
KRUNAL TAILORFreelance Mobile DeveloperCommented:
Hi BobHavertyComh,

FOR IOS
You may try something like this for iOS. For iOS you have option of two types maps. one is apple default map and second is Google Map app. For each of to open from your app, this application is require to installed on your device. If not installed it will not work. See URL Refrence for iOS Map: https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html

NSString *mapstr=[[NSString alloc] initWithFormat:@"http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f",starting address latitude,starting address longitude,destination address latitude, destination address longitude];
            
NSURL *mapurl=[[NSURL alloc] initWithString:mapstr];
[[UIApplication sharedApplication] openURL:mapurl];

Open in new window


Note: All latitude, longitude must be a float value.

For GOOGlE map on ios
http://googlegeodevelopers.blogspot.in/2015/03/open-google-maps-from-your-ios-app.html

Many ref you will get by, Here are some for ios
1) http://www.reigndesign.com/blog/how-to-launch-google-maps-or-apple-maps-from-an-ios-app/
2) https://github.com/googlemaps/OpenInGoogleMaps-iOS

FOR ANDROID

String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", sourceLatitude, sourceLongitude, destinationLatitude, destinationLongitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);

Open in new window


Hope this is what you are looking.

Thanks & Regards,
Krunal T. Tailor
0
 
BobHavertyComhAuthor Commented:
Thanks Krunal
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.