Drongo_III Posted August 12, 2012 Share Posted August 12, 2012 Hi Guys I've been playing around with navigator.geolocation.getCurrentPosition etc. I've written a very basic test script (below). At the moment I am just playing around to get familiar with it before i try something more sophisticated. But I've hit an issue with it and I'm unsure of how to proceed. Basically I've tested the script/page below on two mobiles - both running android. On the more modern phone the browser throws up a prompt asking "do you want to give www.XXXXX.com permission to access to your location?" - hitting the "accept" button then renders out the coords as expected. Great! However, on the other android phone (which is a little older but has google navigator and maps on it so is enabled), I get no prompt for permission and instead an error message is thrown with code 2 - which according to w3c spec. corresponds to: "POSITION_UNAVAILABLE (numeric value 2) The position of the device could not be determined. For instance, one or more of the location providers used in the location acquisition process reported an internal error that caused the process to fail entirely. " So I was wondering if anyone had encountered this type of issue and how they fixed it? It seems to me the reason why it's going to code 2 is because the script doesn't have permission to share location data. But i don't know if, or how, you can specifically seek permission. Any help would be much appreciated! Drongo <script src="jquery1.8.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(successFunction, errorFunction); } else{ $('#location').html("Geolocation not supported "); } // Success Function to obtain coords function successFunction(position) { var lat = position.coords.latitude; var longe = position.coords.longitude; $('#location').html("This is your lat " + lat + " and this is your long " + longe); } // Fail function - outputs error code function errorFunction(error){ var error = error.code; $('#location').html("The error code is " + error); } }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/266973-navigatorgeolocation-location-unavailable/ Share on other sites More sharing options...
Drongo_III Posted August 12, 2012 Author Share Posted August 12, 2012 Hmm well after much messing around with this I've found that if I set the accuracy arg to 'true' (default being false) then it finds my coords. The only problem is that using high accuracy initialises the gps on the phone, which takes around 30-40 seconds. Anyway posting this in case it helps someone. navigator.geolocation.getCurrentPosition(successFunction, errorFunction, { enableHighAccuracy: true}); Quote Link to comment https://forums.phpfreaks.com/topic/266973-navigatorgeolocation-location-unavailable/#findComment-1368801 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.