Reputation: 393
I'm using the function getCurrentPosition
from navigator.geolocation
object. When the user choose share localization or never share I have not problems, but when the user choose "this time not" I can't entry in the function error. This is my code:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, getLocationIp);
} else {
console.log ( "Geolocation is not supported by this browser.");
}
};
function showPosition(position) {
console.log( "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude);
cargarArticulosInicio(position.coords.latitude,position.coords.longitude);
}
function getLocationIp() {
//function get location from ip
}
Upvotes: 2
Views: 63
Reputation: 393
Thanks, I was going crazy with this. I had also thought about creating a boolean variable to control if there is a callback or not. If there was no callback it would still be "false" so I could then call my function getLocationIp, and maybe I could also use setInterval to allow some time for the user to answer.
Upvotes: 1
Reputation: 53280
Unfortunately this is a decision by the browser team for Firefox:
Bug 675533 - Share location- "Not Now" Doesn't fire error callback
This is by design. Not Now hides the popup but allows you to make a decision at a later time, therefore it invokes no callbacks. Never Share will trigger the error callback.
The rationale is that if the user chooses "Not now", it should be interpreted as "I do not want to choose now", therefore it would be as if he/she never answers the question.
At least until he/she re-opens the popup question and chooses another option (Share, always share, or never share, the latter case being the only one calling the error callback).
For sure it would have been nice to get an option to invoke some callback in that case as well. Many people in the referred bug page are asking for it.
Currently the only workaround is to use the timeout.
Upvotes: 1