Software Archive
Read-only legacy content
17061 Discussions

XDK geolocation

Alan_B_
Beginner
1,046 Views

Hi - I'm using the getCurrentPosition method in an XDK build, using the Intel example code (see below).It works fine and returns good latitude and longitude, but fails to return the failure, even with gps, wifi and cellular all turned off (Samsung S3). Instead it just hangs. I guess I could write a JS timeout function, but the thread nature of JS processing makes this a bit problematic. Any ideas?

var getLocation = function() 
{
    var suc = function(p){
        alert("geolocation success");
        if (p.coords.latitude != undefined)
        {
            currentLatitude = p.coords.latitude;
            currentLongitude = p.coords.longitude;
        }

    };
    var fail = function(){ 
        alert("geolocation failed"); 
        getLocation();
    };

    intel.xdk.geolocation.getCurrentPosition(suc,fail);
}

Many thanks - Alan

0 Kudos
6 Replies
PaulF_IntelCorp
Employee
1,046 Views

There are some issues, especially with Samsung devices, and geo data. A fix has been proposed but not yet implemented. This is a general issue with Android devices that varies with the manufacturer. If you search StackOverflow for PhoneGap or Cordova issues related to gps you'll find a variety of solutions. I believe the proposed fix to our container will show up near the end of March, but since it is so hard to test over the wide variety of devices out there, it's not possible to guarantee it will resolve all gps issues.

0 Kudos
Yonas_H_
Beginner
1,046 Views

 Hello Paul F.

Is the geolocation problem yet solved. I am having the same problem as previously posted, Geolocation is not working  on android phones but is working on the emulator.  I am using  navigator.geolocation.getCurrentPosition  for locating the position.

 

 

 

0 Kudos
Hamilton_Tenório_da_
Valued Contributor I
1,046 Views

I am using geolocation plugin with sucess, Android and iOS. No problem on devices. You can see:

- https://play.google.com/store/apps/details?id=com.hamiltonhtsnet.com.br.faleparaowhatsapp

- https://play.google.com/store/apps/details?id=com.hamiltonhtsnet.com.br.fraseprontawhatsapp

- https://play.google.com/store/apps/details?id=com.hamiltonhtsnet.com.br.meurastro

Always CLI 4.2.1 and CW14

0 Kudos
Amrita_C_Intel
Employee
1,046 Views

Hello,

You need to manually switch on the permissions on Android inorder to enable Location. Go to settings, select location and turn it on. 

0 Kudos
PaulF_IntelCorp
Employee
1,046 Views

Yonas, try the "Hello-Cordova" sample to make sure geo works. It provides a very good example of geo and allows you to see if it works or does not work on a specific device.

0 Kudos
Nick_F_2
New Contributor III
1,046 Views

I had major issues on Sony Xperia, it just would not process the Geolocation details, it just sat there doing nothing.

I had to add var options = { enableHighAccuracy: true }; but the knock on effect is that saving the data can take 4 or 5 seconds where as on other devices the data will save in a fraction of a second.

function getLocation(){
var options = { enableHighAccuracy: true };
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(saveReading, onError,options);
}
    else
    {
    navigator.notification.alert("Cannot get Geolocation Data.");
    }
}
function onError(error) {
    navigator.notification.alert('code: '    + error.code    + '\n' + 'message: ' + error.message + '\n');
}

0 Kudos
Reply