You need to sign in to do that
Don't have an account?
AK-2
My VF page can't get geolocation in Salesforce1
I have a VF page that's a simple proof of concept to get geolocation. The page is accessible through Salesforce1. The javascript on the page, makes a call to navigator.geolocation.getCurrentPosition and shows the location on the page. The page works correctly on desktop but through salesforce1, the geolocation.getCurrentPosition doesn't go go to success or error function handlers. I added javascript alerts to try to debug the problem. When viewing the page through salesforce1 I see the alert message "geolocation enabled" that I added in the if (navigator.geolocation) but none of the alerts from the success handler or the error handler show up! (Below is my VF page code)
What am I doing wrong?
Thank you.
What am I doing wrong?
Thank you.
<apex:page controller="testController" doctype="html-5.0"> <label id='test'>No geo-location</label> <script type="text/javascript"> //error handler function showError(error) { alert('in error'); var testElem = document.getElementById("test"); var strError = "Unknown Error"; switch(error.code) { case error.PERMISSION_DENIED: strError = "User denied the request for Geolocation." break; case error.POSITION_UNAVAILABLE: strError = "Location information is unavailable." break; case error.TIMEOUT: strError = "The request to get user location timed out." break; case error.UNKNOWN_ERROR: strError = "An unknown error occurred." break; } alert(strError); testElem.innerText = strError; }; //success handler function successGeo(position){ lat = position.coords.latitude; lon = position.coords.longitude; var testElem = document.getElementById("test"); var strLatLong = 'lat: ' + lat.toString() + ', long:' + lon.toString(); alert('Location: ' + strLatLong); testElem.innerText = strLatLong; }; // detection capabilities with JavaScript if (navigator.geolocation) { var testElem = document.getElementById("test"); testElem.innerText = 'getting geo location!'; alert('geolocation enabled1'); navigator.geolocation.getCurrentPosition(successGeo, showError); }; </script>
Apparently, there is a bug in Salesforce1 and it doesn't ask for permission to access location and that's why the location service was not available. There is a workaround mentioned in the issue by Salesforce and that worked for me.
I am all happy now :-)
All Answers
If you are using in some mobile device you have to turn on location settings.
For IOS check,
https://support.google.com/coordinate/answer/2800543?hl=en
For Android,
https://support.google.com/coordinate/answer/2569281?hl=en
Please let me know if this solves your issue.
--Akram
Not sure what I am missing.
https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation.getCurrentPosition
--Akram
When I open this url on my phone, I get a prompt that says the page would like to use your current location and I have to hit "OK" to let the page use my location. I don't get any such prompt when I use the VF page in Salesforce1 neither do I get that prompt when I start Salesforce1. I am guessing since Salesforce1 doesn't have permission to use location, the VF page is hanging up. I just don't know how to let Salesforce1 use geolocation!
Apparently, there is a bug in Salesforce1 and it doesn't ask for permission to access location and that's why the location service was not available. There is a workaround mentioned in the issue by Salesforce and that worked for me.
I am all happy now :-)
I am facing the same issue now. Were u able to resolve this earlier?
Thanks,
Gautam Manchanda