Software Archive
Read-only legacy content
17061 Discussions

Geolocation on Android in XDK, again

Bill_D_1
Beginner
794 Views

I had a test app that used Cordova geolocation, but no longer works. From what I have read, Cordova has deprecated their geolocation plugin in favor of HTML 5 native geolocation. I've tried that with the code below and it works in the emulator and debug mode, but not in an Android XDK build. I've read previous posts that suggest using the Intel geolocation, but that plugin is still marked as deprecated. What is the correct way to do geolocation in the XDK for multiplatform development.

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.watchPosition(showPosition, showError);
    } else {
        alert("Geolocation is not supported by this browser.");
    }
}
function showPosition(position) {
    alert("location found");
}
function showError(error) {
    alert("error");
}

 

0 Kudos
1 Solution
PaulF_IntelCorp
Employee
794 Views

The Android webviews are not very good about this. If you use the Cordova geo plugin it will defer to the builtin geo if it finds it there, otherwise it will use the plugin implementation. Don't use the Android webviews, that's the main source of your troubles. Use the Android-Crosswalk build instead. I recommend you set the Crosswalk build to 14.

Also, try the geo code in this example, it's more complete: https://github.com/xmnboy/hello-cordova

View solution in original post

0 Kudos
3 Replies
John_H_Intel2
Employee
793 Views

You should follow the code snippets found here https://github.com/apache/cordova-plugin-geolocation

0 Kudos
Bill_D_1
Beginner
793 Views

Thanks for the quick reply. That is the code I had and did not work when I used the XDK Android build process. I'll check it carefully and try it again.

0 Kudos
PaulF_IntelCorp
Employee
795 Views

The Android webviews are not very good about this. If you use the Cordova geo plugin it will defer to the builtin geo if it finds it there, otherwise it will use the plugin implementation. Don't use the Android webviews, that's the main source of your troubles. Use the Android-Crosswalk build instead. I recommend you set the Crosswalk build to 14.

Also, try the geo code in this example, it's more complete: https://github.com/xmnboy/hello-cordova

0 Kudos
Reply