I am trying to get the location of the user with HTML5 geolocation
.
On Desktop it works great, but on all my mobile devices (Samsung note, Samsung galaxy S4 And Iphone 6) its not working and not showing the error
object.
this is my code:
function showPosition(position) {
var coor = position.coords.longitude+", "+position.coords.latitude;
alert(coor);
}
function errorPosition(error) {
alert(error);
}
function toggleGeolocation() {
navigator.geolocation.watchPosition(showPosition,errorPosition);
}
It asks to get permission for geolocation and I click allow (gps is working). What could be the problem?
I am using Google Chrome on all devices.
Try with this code, it should work.
var successHandler = function(position) {
alert(position.coords.latitude);
alert(position.coords.longitude);
};
var errorHandler = function (errorObj) {
alert(errorObj.code + ": " + errorObj.message);
alert("something wrong take this lat " + 26.0546106 );
alert("something wrong take this lng " +-98.3939791);
};
navigator.geolocation.getCurrentPosition(
successHandler, errorHandler,
{enableHighAccuracy: true, maximumAge: 10000});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With