How to get geolocation working on crosswalk cordova

294 views Asked by At

Hello i am creating an application using google nearest places api, which will enable me show the nearest places around a location.

the application works without any errors when tested on a normal web browser or chrome mobile browser as screen shot below

Please click to view

The issue i encounter is when i run this web application via an inapp browser or crosswalk webview plugin for cordova i am unable to get my present location (geolocation dosent work)

Please how can i get my web app get its present location using geolocation via either the crosswalk or inappbrowser

i presume this is an issue of geolocation permissions but i dont know how to solve this

1

There are 1 answers

1
Enzo B. On

If this is issue du to geolocation permissions was missed you can use this plugin for check if there are enable, ask to user to enable it, check if you have the permissions to use geolocalisation and if not, ask the permissions to user :

https://github.com/dpa99c/cordova-diagnostic-plugin

function isAuthorize() {
    cordova.plugins.diagnostic.isLocationAuthorized(function(authorized){
        if (authorized) {
            this.isEnabled();
        }
        else {
            // Do something whenuser don't allowed the localisation
        }
    }, function(error){
        console.error("The following error occurred: "+error);
    });
}

function isEnabled() {
    cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
        if (enabled) {
            // Geolocation is enabled and you have permission to used it
        }
        else {
            // Geolocalisation is not enabled
            // Displays the device location settings to allow user to enable location services/change location mode.
            cordova.plugins.diagnostic.switchToLocationSettings();
        }
    }, function(error){
        console.error("The following error occurred: "+error);
    });
}