In my website I want to get the visitor location with highest accuracy as possible
I used geolocation , It's working and latitude and longitude is returned. But the problem is sometimes they're returned with a very high accuracy sometimes they don't and they are far away from the actual location.
I have included enableHighAccuracy: true what else is needed? what can I do to achive it with high accuracy always? or 99% of the time?
here is sample of the output
Not accurate at all
latitude: ****, longitude: ****, accuracy: 40852
Very Accurate
latitude: ****, longitude: ****, accuracy: 29
The code
function getCurrentLocation() {
console.log("test");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) { //showLocation, ErrorHandler, options
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var accuracy = position.coords.accuracy;
var coords = new google.maps.LatLng(latitude, longitude);
var mapOptions = {
zoom: 15,
center: coords,
mapTypeControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var capa = document.getElementById('lat');
capa.innerHTML = "latitude: " + latitude + ", longitude: " + longitude + ", accuracy: " + accuracy;
map = new google.maps.Map(document.getElementById("mapContainer"), mapOptions);
var marker = new google.maps.Marker({
position: coords,
map: map,
title: "ok"
});
},
function error(msg) { alert('Please enable your GPS position feature.'); }
,
{ maximumAge: 10000, timeout: 5000, enableHighAccuracy: true });
} else {
alert("Geolocation API is not supported in your browser.");
}
}
Based on my own experiences making a lot GPS applications for Sailing and Golfing for various devices, I think that the Accuracy is estimated very conservative.
Since I make app for phones (using navigator.geolocation as well) Samsung watches (also geolocation.navigator) Apple Watch and Fibit I did quite some tests. On Golf courses I have the coordinates of the flag and on the golf course there are distance markers that are correct. Also, fellow golfers use lasers to get distance to the flag. While the app shows you an accuracy of 15 meters, in reality is not more than 5 and usually less than 5.
What you can do as test is to load a google Satellite map and then show your current position on it.
now enableHighAccuracy does not guarantee a position based on satellites but can be based on cell towers/ wifi networks as well depending on the device. The accuracy slowly improves when more satellites are found. A clear view of the sky without buildings around you is the best. Even after half an hour the accuracy still improves. Satellites lower on the horizon are hard to find but improve accuracy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With