I have a website that asks for geolocation. It should only ask the first time you open the website but I noticed that if you open the website on mobile (with Chrome or Safari) or on desktop with Safari, the website asks for permission every time you reload a page.
If you open the website on a computer with Chrome it works as it should without any problems.
This is my code. What is the cause of this issue?
jQuery(document).ready(function($) {
if ("geolocation" in navigator) {
console.log("Geolocation availbale");
navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError);
} else {
geolocationError()
}
function geolocationSuccess(position) {
console.log(position.coords.latitude, position.coords.longitude);
$.ajax({
url: geolocationParams.ajaxurl,
type: 'POST',
data: {
action: geolocationParams.actionLocalities,
lat: position.coords.latitude,
lng: position.coords.longitude,
},
dataType: 'json',
success: function(response) {
console.log("Ajax returned", response);
$('.homepage-posts-wrapper.third-block-grid').html(response.html);
}
})
}
function geolocationError(err) {
console.log(err);
$.ajax({
url: geolocationParams.ajaxurl,
type: 'POST',
data: {
action: geolocationParams.actionLocalities,
lat: "",
lng: "",
},
dataType: 'json',
success: function(response) {
console.log("Ajax returned", response);
$('.homepage-posts-wrapper.third-block-grid').html(response.html);
}
})
}
});
