I was really struggling to make a title for this one. I hope it’s okay.
I have a website with several office-locations. I would like to send the user to google maps with the location of the selected office, and i would also like to use the location of the user.
This website is for mobiles only.
I’ve done some research, and I’ve found one possible method to do this, but i cant’ but wonder, there has to be an easier way to do this. Using a whole lot of code to see which language the users browser is, and then pass on “Current+Location” into the href in the correct language seems weird considering its Google.
I’m using the following href right now, where i will be adding a dynamic location for the offices.
<a href="http://maps.google.com/maps?f=d&source=s_d&saddr=CURRENTLOCATION&daddr=OFFICELOCATION&hl=en&geocode=Ff7kxwMdn62eAClBW-CUmzFtRjG-TdPYIg6PMw%3BCVVCpEO5eoJYFdnnxwMd5LKeACEJ5__6cDooDym1URz6mzFtRjFiK54FolriNQ&mra=pe&mrcr=0&dirflg=w&doflg=ptm&sll=63.408475,10.396459&sspn=0.102044,0.33783&ie=UTF8&z=19
">Directions</a>
Its the CURRENTLOCATION I’m not getting a hang on how to do.
Most smartphones have HTML 5 browsers. You can utilize the HTML 5 Geolocation spec to retrieve the users current position.
http://www.w3schools.com/html/html5_geolocation.asp
Then either send the lat/long directly to google maps, or do a reverse geocode look up using google maps rest api’s.
https://developers.google.com/maps/documentation/geocoding/