Reputation: 2171
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
Upvotes: 8
Views: 14860
Reputation: 1
For me, it was just a security problem, in local host getCurrentPosition
does not work but on GitHub page it does !
Upvotes: 0
Reputation: 53
For me, Chrome appears to be the problem - the browser doesn't allow insecure origins like HTTP. Should be solved by transferring the data over HTTPS (see Chromium). Worked on my Galaxy S7 Edge when trying in an alternate browser.
Upvotes: 1
Reputation: 11
I had the same problem on my Galaxy GT-N8013 tablet, the getCurrentPosition seems not working on android but it does work on ios. To fix the issue, first I increased the timeout. Second, open google map app. Third, restart the tablet. It works after that.
$cordovaGeolocation.getCurrentPosition({timeout: 30000, enableHighAccuracy: false})
Upvotes: 1
Reputation: 11
I have a Samsung Galaxy Trend Plus GT-S7580. The geolocation on my website was not working with this device. Earlier it had work with a Asus surfpad, and every setting open for access to and from Internet. As soon as I allowed not only mobile data access to my place, but also wifi network and the Google access and collection of data connected to this setting, it started to work. In this case it was only that setting.
Upvotes: 1
Reputation: 61
I had something very similar happen to me. The GPS would work fine on every other device but it would error out on Galaxy devices.
What I found out is that it can take upwards of 10 seconds to get a GPS location on these devices. I also had to turn enabledHighAccuracy
to false. Here is my code.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function(position) {
// success!
},
function() {
// failed to get a GPS location before timeout!
}, {
enableHighAccuracy: false,
timeout: 10000,
maximumAge: 10000
});
} else {
// no support for geolocation
}
Hope this helps!
Upvotes: 2
Reputation: 1371
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:
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,
Upvotes: 22