For more details here.
Now we can obtain the location of the user like so :
To handle any errors, we can use second parameters of getCurrentPosition(). If anything fails, it will invoke the error callback, letting us update the user with corresponding error message. Let’s break it down a bit for your understanding.
In the third parameter of getCurrentPosition(), the enableHighAccuracy attribute tries to provide best results, but this may cause slower response and can increase the power consumption of the device.
Geolocation can be used in many different ways, it can be used to store location info of pictures taken in various points, pinpoint exact location of a lost user in unfamiliar city or update user location on social media sites. But you should also be aware that the implementation of Geolocation varies device to device, some support this feature and others don’t, the result entirely depends on hosting device and accuracy is not guaranteed!
You should also be very responsible when using one’s location data, since it discloses the location of the user, thereby potentially compromising the user’s privacy. It’s always a good idea to setup HTTPS on your website before making geolocation API requests. Goodluck!