So I have this javascript code. In safari and chrome, if user declines to share location, it goes to fail function as it should; however, in Firefox, it does not.
Any helps appreciated.
function initGeolocation() { if( navigator.geolocation ) { // Call getCurrentPosition with success and failure callbacks navigator.geolocation.getCurrentPosition( success, fail ); } else { alert("Sorry, your browser does not support geolocation services."); } } var map; function success(position) { var longIDText = document.getElementById('longID'); var latIDText = document.getElementById('latID'); longIDText.value = position.coords.longitude; latIDText.value = position.coords.latitude; document.getElementById('coordSubmitID').click(); } function fail(error) { alert("FAAAAAAAAAAIIIIIIIIIL") var zip_code ; while (true){ // Could not obtain location zip_code = prompt("Please enter your current address or zip code",""); if ( zip_code == "" ) { alert(zip_code +" is not a valid address. Please try again."); } else{ break; } } var zipIDText = document.getElementById('zipID'); zipIDText.value = zip_code; document.getElementById('coordSubmitID').click(); }
If you have enabled the “Attempt to auto-locate the user” option on the settings page, and it doesn't work in Chrome, Safari or Firefox, then this is likely because of an insecure connection.
The Geolocation. getCurrentPosition() method is used to get the current position of the device.
If you receive this error, it means your device supports geolocation but your mobile browser is unable to access it. To fix this, you need to have two things right: Your mobile device's location services (GPS) needs to be enabled. Your mobile browser needs to have an access to the geolocation provided by the phone.
The Geolocation method watchPosition() method is used to register a handler function that will be called automatically each time the position of the device changes. You can also, optionally, specify an error handling callback function.
For Firefox it seems that PERMISSION_DENIED
is raised only if "Never share" is selected; if the dialog is dismissed or "Not now" is selected, effectively nothing happens - even on mozillas geolocation demo if you dismiss the permissions UI nothing happens.
This means that getCurrentPosition
can return either because the user closed the confirmation UI, or because it successfully started it asynchronous request - there doesn't appear to be a way to discriminate between the two.
https://bugzilla.mozilla.org/show_bug.cgi?id=675533
This is a real pain, and definately not desirable functionality.
The workaround I am using to save the user waiting for ever is to set a timeout to check if the wait spinner is showing after 3 seconds, and if so, hide it and show a manual zip code input:
var latlng; var waitTime = 3000; try { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function (position) { success(position); }, showError); } else { showError("NOT-SUPPORTED"); } var t = setTimeout(function () { if ($("#getZip div.loading").css("display") != "none") { $("#getZip div.loading").hide(); $("#errorZip").show(); } }, waitTime); } catch (evt) { alert(evt); }
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