Skip to content Skip to sidebar Skip to footer

Open Google Maps App From A Browser With Default Start Location On Android And Iphone

I have a mobile site and I have a link that can open the google maps native app on iphone and android with default start and end locations by using the link format: http://maps.goo

Solution 1:

I simply replace the values in the following string with my start and destination Lng/Lat

http://maps.google.com/maps?saddr=START_ADD&daddr=DEST_ADD&ll=START_ADD

Then I launch the url like this in android, which will let the user choose to either use the browser or their native maps app:

Stringurl="http://maps.google.com/maps?saddr=START_ADD&daddr=DEST_ADD&ll=START_ADD";

startActivity( newIntent(Intent.ACTION_VIEW).setData(Uri.parse(url)));  

For iOS, if you prefix the url with maps:// instead of http:// it will launch the maps application on the phone which works really well. Something like

NSString *url = @"maps://maps.google.com/maps?saddr=START_ADD&daddr=DEST_ADD&ll=START_ADD";

[[UIApplication sharedApplication] openURL:[NSURL urlWithString:url]];

That is the way I have chosen to handle it. Its pretty easy on either device to get the current Lng/Lat using their respective location frameworks. The results always seem pretty accurate to me as well, you can specify in either how accurate you want the results. The more accurate, the more drain on your battery and sometimes it takes longer to acquire but that's usually something you tweak in the end to get the best results for your implementation.

Solution 2:

Take a look at the url handler geo to tell Browser to use native App

<ahref="geo:50.066274, 10.754427;">Location here!</a>

There is a polyfill script available which would be worth a try for fallback for Desktop Browsers: https://github.com/prowestgis/dojo-geo-uri-polyfill

You may try also for IOs devices those:

comgooglemaps://?parameters

or:

comgooglemaps-x-callback://?parameters

https://developers.google.com/maps/documentation/urls/ios-urlscheme

Solution 3:

I know I could also conditionally check for the user-agent and create the link accordingly but I was hoping that there would be a more elegant way to do this.

This IS the most elegant solution. The two platforms differ too much, to do this with the same link for both platforms. Add Blackberry or Windows Phone in the equation, and you will have even more difficulties in achieving the same behaviour without checking the user-agent

Solution 4:

In Iphone you can get the current location by using CLLocationManagerDelegate in the following method.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{

    CLLocationCoordinate2D location = newLocation.coordinate;
    Float x = location.latitude, y = location.longitude;
}

Post a Comment for "Open Google Maps App From A Browser With Default Start Location On Android And Iphone"