I have written a JavaScript to get user geolocation. It gives me latitude and longitude and according to that I have plot user location in map, but when I check that location latitude and longitude in Google map it’s different so that it plot me wrong place.
function map()
{
if (navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function (position) {
initialize(position.coords.latitude,position.coords.longitude);
}, function () {
handleNoGeolocation(browserSupportFlag);
});
} else {
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
Please let me know how I can get accurate latitude and longitude by using navigator.geolocation.
The Geolocation feature works by using geographical location information available through various sources used depending on the device. This includes satellite data, radio tracking devices, Internet hardware as well as wireless communication equipment.
More precisely the system makes use of GPS, RFID, IP address, Wi-Fi and Bluetooth Mac IDs or mobile phone towers and handset IDs. So, if you are trying on browser then that would depend on the browser and its settings. It might use GPS, WLAN AP-based location, IP location, or any other conceivable method of locating itself.
The browser runs on your local machine, so even if you’re behind a proxy, it should be able to find your actual IP address (unless security features prevent it from being sent for lookup to a geolocation server).
else
if you are trying on mobile device with gps turned on then it should provide results with good accuracy as from my past experience with geolocation api