How to locate users position in map using html5 geolocation

Html5 geolocation API enables you to identify the user’s position. The common sources of geolocation are Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs, as well as user input. There is no guarantee for approximate position.

Using getCurrentPosition() method, you can get the users position in the form of JavaScript Object. This object contains coordinates of the user’s position on the map.


Due to users privacy, User’s position will not be available unless the user approves it.

The basic usage of HTML5 geolocation is:

Note: Run it with you browser, you get an alert with your coordinates..
Use watchPosition() To locate the user’s positions on move,

Extended usage:


How to locate user’s position in the map.

We use Google maps API to generate a map with user coordinates, take a look at the complete code.

Watch demo :

With Google reverse geocoding, you can get the address with the latitude and longitude.
The complete code: