Location Services

📘

If your app requires access to the device location in Android you can either enable this permission in your app configuration to prompt for permission when the app is loaded or you can call a JavaScript Bridge command to request permission at runtime. For iOS permission is only prompted at runtime but to avoid both the app and your website prompting twice for location permission you will need to use the function `gonative_geolocation_ready()` which is called when the location is available within the app.

Disable double location prompt on iOS

The app will override your website's geolocation permission prompt so that only the app will ask for permission.

However the web-based geolocation is overridden with the native one only after the page has loaded. So there is a potential timing issue if you call the JavaScript geolocation request before the native one has been called.

The solution is that once the app is finished doing the native binding a javascript function gonative_geolocation_ready() is called

So, you will need to delay the location prompt until that function is called. For example:

if (navigator.userAgent.indexOf('GoNativeIOS') > -1) {
    function gonative_geolocation_ready() {
         // call navigator.geolocation.getCurrentPosition in this function
    }
} 
else {
    // call navigator geolocation.getCurrentPosition right away directly
}

Prompt user to enable Location Services on Android

If you do not have Location Services permission enabled in your app configuration, you may dynamically prompt for permission by using the following GoNative JavaScript Bridge command.

↔️GoNative JavaScript Bridge

gonative.geoLocation.promptAndroidLocationServices();

If location services are already enabled, the above bridge command will have no effect. If they are disabled, the user will be shown a dialog asking them to enable location services. Note that this is independent from your app's location permission.