HTML Geolocation API is used to fetch geographical position of a user. It can be possible only the user approves it. Geolocation is more accurate for the GPS Enabled mobile devices and others less accuracy. In this post how retrieve the address using Geolocation and Google Map API.
errorMessage = "User denied the request for Geolocation."
errorMessage = "Location information is unavailable."
errorMessage = "The request to get user location timed out."
errorMessage = "An unknown error occurred."
Call getLocation() function by click on 'Find Address' button and checks the browser supports GeoLocation API using navigator.geolocation object, if yes then call navigator.geolocation.getCurrentPosition() with showPosition() as a call back function if the location lookup was successful. The browser calls showPosition() function with current location using position object, which has longitude and latitude as properties.
Using Google MAP API to get address from the longitude and latitude values, for that we call getAddressFromLatLang function. Inside the findAddress() function, I've create an object of google.maps.Geocoder and calling its geocode() method with latitude and longitude and it returns array of addresses for that location.