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.google.com/maps?saddr=XX&daddr=XX.
My problem is, I want to be able to set the starting location to be the current location, and I want it to work from both android and iphone browsers. From my experience, if I leave the saddr blank, in android this defaults to the current location but on iphone it just leaves the start location blank. If I set the saddr to "current location", this sets the start location to be the current location on iphone but on android it doesn't recognize the location.
My solution right now is to use the user's geo lat/long coordinates as the start address. This works successfully across both platforms but depending on the method used to get the coordinates, it may not be as accurate as the user's current location from the gps on the app. I was wondering if there was some way to get the link to open the native app with the correct "current location" for the starting point. 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.
Look to the top-left corner of the map, and click the three horizontal menu bars. From the options, select Your places. Next, click Home. Type the name of the location you want to set as your home address in the address field.
If the Google Maps app is not installed, the map view will open in a mobile browser or in the default Maps app. , followed by Open View in Google Maps. If Google Maps is installed, and the zoom level selected is valid, Google Maps will open and display the same map view.
Tap the menu icon in the top left of the search bar. Scroll down to the bottom of the menu and tap Settings. Tap Default apps. Under Navigate from your location, tap Google Maps, then under Navigate between locations, tap Google Maps again.
As good as it is, though, Google's version of Maps for iOS 6 is quite different from its Android counterpart in ways big and small. Rather than port a quick-and-dirty Android doppelganger over to the App Store, the Google Maps team designed a uniquely iOS interface and experience.
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:
String url = "http://maps.google.com/maps?saddr=START_ADD&daddr=DEST_ADD&ll=START_ADD";
startActivity( new Intent(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With