Each time you press the button, a new row of location data will be added here
This shows how to use various APIs to try to find the location of the user of your website. It tries several techniques to find the user's location, starting with the most precise and then moving onto less precise methods.
First it will try to use the W3C geolocation standard. At time of writing this is supported in the latest versions of the main browsers and seems to be very accurate sometimes and reasonably accurate other times (even from the same location). The only problem with it is that it asks the user for permission before proceeding, which means you'll need a fallback solution if the user says no.
As a fallback, the location will be guessed based on the user's locale. This is pretty inaccurate and may be completely wrong, if the user has set their locale to something not related to their actual location. My mapping of locales to locations is not complete so this method also may not work at all.
There used to be a thing called Google Loader that also provided this functionality, but that no longer exists as far as I can tell
Browser | API supported |
---|---|
Microsoft Edge | W3C over HTTPS |
Internet Explorer 9+ | W3C |
Chrome 50+ | W3C over HTTPS |
Chrome 9 - 49 | W3C |
FireFox 3.6+ | W3C |
Safari 5 | W3C |
Opera 11 | W3C |