I am using navigator.geolocation.getCurrentPosition()
to get user's current location. The location feature on these web pages works fine when loaded directly into a web browser on both iOS and Android. User gets asked if they allow access to location, and it goes from there. Doesn't matter which web browser or OS--they all work fine.
However, if the same webpage is loaded in a web browser embedded in an app running on Android (TWebBrowser component in this case), the location service does not work. A call to navigator.geolocation.getCurrentPosition()
results in permission_denied
error message. User is NOT even asked if they would allow access to location; it just raises permission_denied error.
Some of the obvious things that I checked:
if (navigator.geolocation) {
so I know that
geolocation capability is there. I tried it on several Android devices with different Android versions all the way up to the latest v6, and they all behave the same. That leads me to think that I am running into some Android OS "feature". Is there any way around it as my apps functionality depends on access to location services from the webpage as well.
As a workaround, I am passing current location to the webpage in parameters when calling it from the app. But I can't use WatchLocation to update the position on map when user moves around.
you can use this code to check for permissions first
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}