1

I have created one app which locates the GeoLocation coordinates on iPad/iPhone but fails to do so on some of Android device even when the device is GPS enabled.It works on some of the Android Device(e.g Samsung Galaxy tab SCH-I800) and fails on some other(e.g Samsung Galaxy tab GT-P5113).

Any idea what could be the possible reason for the issue?

Sample code snippet:

 <script type="text/javascript" 
 src="http://maps.google.com/maps/api/js?sensor=true"></script>
 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true">   </script>
    <script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>

function onDeviceReady()
{  
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}

var onSuccess = function(position) {

            pos = new google.maps.LatLng(position.coords.latitude,
                                         position.coords.longitude);
            lat=position.coords.latitude;
            lng=position.coords.longitude;
            alert("lat: "+lat+" long "+lng); //i should get the lat/long here which i need to use further in my code   
         }

for devices where the app is not working it's going to onError function.

function onError(error) {

      alert("error code is: "+error.code);//it gives error code 3 when on such devices


        }
Mayukh Raaj
  • 403
  • 2
  • 7
  • 19

4 Answers4

1

You need to set the "enableHighAccuracy" option when setting up the watch to use GPS on those Android devices:

navigator.geolocation.watchPosition(onSuccess, onError, { enableHighAccuracy: true });

See this answer also: Phonegap Android and GPS satellite

Community
  • 1
  • 1
DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • 1
    I have already tried with "enableHighAccuracy".It doesn't work with that also.Also i think that this property is more related to accuracy whereas My problem is i am not getting any location only on those devices. – Mayukh Raaj Dec 27 '12 at 09:19
0

Your app doesn't work because of this error:

PositionError.TIMEOUT

Returned when the device was unable to retrieve a position within the time specified in the geolocationOptions' timeout property. When using in conjunction with geolocation.watchPosition, this error could be called into the geolocationError callback every timeout milliseconds.

A. Magalhães
  • 1,511
  • 2
  • 22
  • 31
  • Yes it gives timeout error but only on some specific devices and on the other it works.That's strange because when i tried to look for my location on map using that device it showed me current location but failed to do so with app even when on other devices it showed up the location. – Mayukh Raaj Dec 27 '12 at 12:23
  • Do you need this code: pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);? – A. Magalhães Dec 27 '12 at 12:29
0

Set the "enableHighAccuracy" option to false and then if you get code 2 error ( u might get sometimes ) , just

Go to

Menu--->Settings---->Location & Security

and then check

Use Wireless Network.

This has solved my problem and hope it solves yours as well...!!

user1989040
  • 167
  • 3
  • 12
0

I had this problem with one if my projects and my customer was adamant that he could go into maps and it would find Hus geolocation almost immediately whereas in my app it took forever or didn't work.

The solution was to go back in time on the plugins git repository and find the java files that were removed, and use that version.

What has happened is the plugin maintainers have just used the native browser geolocation , essentially not using a plugin at all, but in some phones it's just not up to scratch. An alternative could ve to use crosswalk in your app.

I know its not a "good" solution, but its what was necessary to get an acceptable performance.

Ryan Knell
  • 6,204
  • 2
  • 40
  • 32