2
I recently started using the Google Maps API, so I know very little about.
When entering the site of my project the browser asks if it can obtain the user’s location. Only I realized that the location varies depending on the browser. Using Google Chrome the location is very precise but if you access with Firefox or Edge is totally different..
Why does this variation of location occur?
Google Chrome (@-23.6058457,-46.6586903,18.25z)
Mozilla Firefox (@-23.6083054,-46.6559814,18.4z)
Microsoft Edge (@-23.5346485,-46.6277816,16.91z) - Far from my location.
There’s something I can change in my code to correct this inaccuracy?
var geocoder;
var map;
var marker;
function initialize() {
var latlng = new google.maps.LatLng(-18.8800397, -47.05878999999999);
var options = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMaps"), options);
geocoder = new google.maps.Geocoder();
marker = new google.maps.Marker({
map: map,
draggable: true,
icon: 'images/mapicon.png',
});
marker.setPosition(latlng);
}
// verifica se o navegador tem suporte a geolocalização
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) { // callback de sucesso
// ajusta a posição do marker para a localização do usuário
//marker.setPosition(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(initialLocation);
marker.setPosition(initialLocation);
},
function (error) { // callback de erro
alert('Erro ao obter localização!');
console.log('Erro ao obter localização.', error);
});
} else {
console.log('Navegador não suporta Geolocalização!');
}
Antonio, thanks for the feedback. :/
– Gabriel Bernardone
So, like I said, he tries to get a higher precision, but he might not make it. Google certainly has more resources to get better locations than its competitors, Chrome can, for example, use Streetview data to help with accuracy (Streetview cars collect data from the wifi networks they pass through). I will edit my post by adding another method that may help you, but you will always be restricted to the capabilities and resources of each browser and, as for this, there is nothing to do.
– Antonio Carlos