Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Samsung Galaxy Devices can't use geolocation.getCurrentPosition

OK, so I've been looking for an adequate response to this issue for quite some time. I have a web application that uses navigator.geolocation.getCurrentPosition to get a user's position.

The native browser on the Samsung Galaxy devices nearly always have problems with the getCurrentPosition code. I have tried all kinds of variations of this code with callbacks and timeouts, but its always the same issue. Plenty of people have documented this issue, and some indicate that restarting the device will work (sometimes restarting does work, but not always - and an alert telling users to restart their device seems beyond rediculous).

Has anyone figured out a surefire way to use getCurrentPosition to work on a Samsung Galaxy Device? Here's what I'm working with...

<script>

$(document).ready(function(){

if( navigator.geolocation ) {
    navigator.geolocation.getCurrentPosition( success, fail );
}

else {
     alert("Sorry, your browser does not support geolocation services.");
}

function success(position) {

    window.location = "mobile_set_coordinates.php?user_lat=" + position.coords.latitude + 
    "&user_lon=" + position.coords.longitude + "&accuracy=" + position.coords.accuracy;
}

function fail() {
    // Could not obtain location
}

});

</script>

Also, here's a link to one of the discussions regarding the issue: https://groups.google.com/forum/#!topic/phonegap/ESrHAjFHgFU

like image 466
Brandon Avatar asked Aug 07 '13 10:08

Brandon


People also ask

What is navigator geolocation getCurrentPosition?

Description. The getCurrentPosition method retrieves the current geographic location of the device. The location is expressed as a set of geographic coordinates together with information about heading and speed. The location information is returned in a Position object.

What is geolocation maximumAge?

maximumAge. A positive long value indicating the maximum age in milliseconds of a possible cached position that is acceptable to return. If set to 0 , it means that the device cannot use a cached position and must attempt to retrieve the real current position.

How do I get geolocation on my browser?

The Geolocation API is accessed via a call to navigator. geolocation ; this will cause the user's browser to ask them for permission to access their location data. If they accept, then the browser will use the best available functionality on the device to access this information (for example, GPS).

What is the significance of the first parameter in getCurrentPosition () API?

The error callback function, if provided when calling getCurrentPosition() or watchPosition() , expects a GeolocationPositionError object instance as its first parameter.


1 Answers

I got exactly the same problem as you have few weeks ago. I tried to research about 2 weeks on the internet, look into all solutions that I can find. After all, I found out that:

  1. If Google Maps has never been open on your target phone, this function does not work.
  2. Reset your GPS state, then restart your phone. It might help.
  3. If step 2 does not work, reset the state of the GPS, turn on get Time Zone automatically on Date Time setting, then restart your phone.

According to my knowledge, there is nothing wrong with the code. In fact, my code is nearly the same as yours. It happens not only on Galaxy devices but also on some HTC. I faced with this problem on Galaxy S2, Galaxy Note 2, HTC Nexus One, HTC One X and HTC Incredible S. I think it should be the problem between the Android devices and the competition of the code somehow.

Cheers,

like image 66
Long Dao Avatar answered Oct 05 '22 23:10

Long Dao