Reputation: 403
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
}
Upvotes: 1
Views: 2562
Reputation: 6322
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.
Upvotes: 0
Reputation: 167
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...!!
Upvotes: 0
Reputation: 1516
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.
Upvotes: 0
Reputation: 30356
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
Upvotes: 1