Mobile web driving directions from current location
Asked Answered
R

4

8

I'm building a mobile-version of a website, trying to have one-click link to launch Google Maps with driving directions to the business, from the user's current location. I have it working fine for the iPhone, but when testing on Android, it views 'Current%20Location' and tries to find a business called 'Current Location'. Here is my current code:

    <a href="http://maps.google.com/maps?saddr=Current%20Location&daddr=123 Street Rd,Cityville,MD,21098">Get Directions</a>

I need a universal string to search from the current location, and can't find a definitive answer anywhere online.

Thanks in advance for any help!

Recruitment answered 12/9, 2011 at 20:1 Comment(0)
D
7

I am doing the same thing and now have it working on Android. I don't have an iPhone so I have no way of testing on that. You should leave the saddr parameter blank in the URL, and Google Maps will then prefill it with the user's current location. Also, use + signs instead of spaces in the destination address. Here's the corrected URL:

http://maps.google.com/maps?saddr=&daddr=123+Street+Rd,Cityville,MD,21098

Dionysian answered 5/5, 2012 at 23:54 Comment(1)
To make this link work on an iPhone, just change the 'saddr' value to "Current Location". Like this. http://maps.google.com/maps?saddr=Current%20Location&daddr=123+Street+Rd,Cityville,MD,21098 More details on the Google map API are here.Spilt
M
0

Use the google gps api to get the currentlocation and pass it to maps. Even better I think there's an action to open the built-in maps application asking it to route from current location to your address.

This article on location services should help http://developer.android.com/guide/topics/location/index.html

If you're trying to do it fully through the web, I think the user has to enable location services on the google webpage for it to work.

Also, check out this javascript library that provides a platform neutral api for gps services on most devices http://code.google.com/p/geo-location-javascript/

Mcnalley answered 12/9, 2011 at 20:7 Comment(2)
Thanks for the quick response, but I'm trying to keep this very simple. This isn't an app, it is just a mobile-version of a website. Like I said, the code above (simple <a> link) works fine for the iPhone; trying to find a simliar syntax for Android. Basically, I just need to find a common syntax for 'Current Location' that works between iPhone and Android.Recruitment
That geo-location javascript library might be your best bet, like I said it appears to handle what you need for all the mobile platforms.Mcnalley
T
0

Google Maps with directions from current location

https://maps.google.com/maps?saddr=&daddr=35.658157,139.697174&sensor=TRUE

https://maps.google.com/maps?saddr=&daddr= PLUS

"location's_latitude" PLUS

"," PLUS

"location's_longitude" PLUS

"&sensor=TRUE" // for getting your current location

Probably the most accurate way using lat and long

Tanner answered 23/1, 2014 at 13:11 Comment(0)
L
0
<span class="addressAt">
     <a href="http://maps.google.com/maps?f=d&amp;hl=en&amp;region=US&amp;doflg=ptm&amp;geocode=&amp;saddr=&amp;daddr=41.75553,-88.322048" target="_blank">213 S River St
Aurora, IL</a>
</span>

This is the only way to get an accurate "my location" on the google maps mobile site. Replace the coordinates(41.75553,-88.322048) with your locations coords. All other ways just wrote in my location as the start address without actually getting the real time location.

Lorianne answered 3/6, 2014 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.