My website requests geolocation permission but has a recurring issue. When accessed on mobile (using Chrome or Safari) or desktop Safari, the permission prompt pops up every time a page is reloaded.
However, when accessing the site on a computer with Chrome, everything works flawlessly.
I've included my code below. Can you help me identify the cause of this problem?
jQuery(document).ready(function($) {
if ("geolocation" in navigator) {
console.log("Geolocation available");
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);
}
})
}
});