If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

java script geo tracking website users for directions

I have a google map on my site. and i have a form that auto fills the persons lat and long when they fill it out.

what i want to do is make the map on my main page show my office as a waypoint which it does... and then get there lat and lang to provide them with directions to my office.

I would provide code but i have recoded this 100 times today have ten hours in to it and still can not get it to work... will someone please write a script for me and explain it line by line so I
can understand where I have been going wrong?

i was planing on setting a waypoint to the office. so it can not be changed. then who ever is using the website url accepts us using their location so we can immediately give them directions straight to the shop from out home page. employees work in the field and carry tablets and laptops... it would be nice to have everything centralized on one site which is what i have been doing.

i want the url to grab the lat and long from the user and automatically set their directions up to the office in the map in the footer.

But I would recommend building in some error handling in case:
a) geolocation fails
b) the user refuses to share their location
c) the geolocator gets confused (between, say paris, france and paris, texas)
d) geolocation succeeds, but is a few km off (which is not at all rare - I have seen it return results that were several hundred kilometers off target)

The meridian distance (a distance on a longcircle) is 111,111 km for one degree (40 000 km for 360°, it's the meter definition) or 1 852 mètres for one minute (111,111/60 km the nautical mile definition).

The length of a degree of longitude (a distance on a parallele) depends of the radius (or the circumference) at this parallele which is 111,111 * cos(lat) km (or 40 000 * cos(lat) km for the circumference).

Then the route for a little move (no more than a few degrees) of deltaLat, deltaLng from a Point (lat,lng) is given by an an angle (mesured clokwise from Nord).
Route = 90° - 180*Math.atan2(deltaLat, Math.cos(lat)*deltaLng)/Math.PI

</script>
#################################################
and this is code i have on seperate page for putting a roadmap in with a wavepoint.
#############################################################

here is something similar that I made a while ago (so please forgive the ugly coding). If geolocation fails, it falls back on IP lookup. And if the geolocator gets it wrong, you can drag your location or type in a new one. Geolocation isn't working here either (Guatemala), but last time I looked when it was working, the code worked OK. Let me know if you have any questions...

The script you sent me is not functional. It shows map and submit button but nothing happens. Nor does it get my location... any ideas?

oops - you are quite right... I forgot to call the directions function after it gets the location

try this one. I have added alerts so you can see when it is working with geolocation and when it falls back on IP lookup.

Some browser notes on geolocation:
Firefox just fails here (here being where I live), without notification
Chrome gets the location fine, as long as you give it permission
IE is crap, so you know what it does...

Thanks all

I have it working. Things to learn from this. Stacking g map api gets tricky. It causes errors.
Making sure to have your calls set properly such as on load or on click are important. Making the same call twice will cause problems. Such as having a map in your footer.php and your current page. Even referencing the google api in your header twice on two different pages that include on one page is bad. It works it's awesome and I've learned a lot from the past five days of all who contributed