2
I would like to know, if I have to give some kind of permission, for the code to work in Chrome, because in mozila it can give me the location. Follow the code below`
function writeAddressName(latLng) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
"location": latLng
},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
document.getElementById("address").innerHTML = results[0].formatted_address;
else
document.getElementById("error").innerHTML += "Unable to retrieve your address" + "<br />";
});
}
function geolocationSuccess(position) {
var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// Escreva o endereço da localização
writeAddressName(userLatLng);
// Coloque o marcador na posição do usuario
new google.maps.Marker({
map: map,
icon:'img/aqui',
position: userLatLng
});
// Desenhe um círculo em torno da posição do usuário para ter uma idéia da precisão de localização atual
var circle = new google.maps.Circle({
center: userLatLng,
radius: 500,
map: map,
fillColor: '#0000FF',
fillOpacity: 0.3,
strokeColor: '#0000FF',
strokeOpacity: 1.0,
});
map.fitBounds(circle.getBounds());
}
function geolocationError(positionError) {
document.getElementById("error").innerHTML += "Error: " + positionError.message + "<br />";
}
function geolocateUser() {
// Verifica se o navegador suportar a Geolocation API
if (navigator.geolocation)
{
var positionOptions = {
enableHighAccuracy: true,
timeout: 10 * 1000 // 10 seconds
};
navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, positionOptions);
}
else
document.getElementById("error").innerHTML += "Your browser doesn't support the Geolocation API";
}
window.onload = geolocateUser;
getCurrentPosition() and watchPosition() no longer work on insecure Origins. To use this Feature, you should consider switching your application to a Secure origin, such as HTTPS. See https://goo.gl/rStTGz for more Details.
– Pedro Augusto