0
I’m putting geolocation on a client site, only I’m having a problem doing some function that calls a alert()
if the user does not give permission for the browser to use geolocation. What I want is just to display a alert()
when the user denies. My current code
var map;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var latlng = new google.maps.LatLng(-18.8800397, -47.05878999999999);
var options = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("mapa"), options);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("trajeto-texto"));
}
function getPosition(){
if ( navigator.geolocation ){
navigator.geolocation.getCurrentPosition( function( posicao ){
var positions = new Array();
positions['latitude'] = posicao.coords.latitude;
positions['longitude'] = posicao.coords.longitude;
initialize();
var enderecoPartida = '08210-791, Brasil';
var enderecoChegada = '08215-255, Brasil';
var request = {
origin: enderecoPartida,
destination: enderecoChegada,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
} );
}
}
getPosition();
I tried to leave that line Navigator.geolocation.getCurrentPosition( Function( position ){ thus Navigator.geolocation.getCurrentPosition( Function( position, error ){ but it didn’t work out.
Oops, I didn’t get to use the google maps api, but an idea here... You can set a function with settimeout(Function(){},time); and check if it has contents inside the div map, if it has content is pq loaded, correct?
– rafaelphp
yeah, and how would that check ? has some sample code there? I’m not so good with JS. I researched here and the problem seems to be in Ubuntu Firefox, which is what I use, but I saw people doing something with setTimeOut() only I was in English and ignored.
– Alisson Acioli