I am using geolocation api to know the customer's location. 1)If the customer select on share location I send the latitude and longitude to another page using ajax to build the result page which contains data for their location. 2) If the customer don't want share the location I want to send other data using ajax.
<script>
window.onload = function() {
var startPos;
var geoSuccess = function(position) {
startPos = position;
var x= startPos.coords.latitude;
var y= startPos.coords.longitude;
$.post("<?php echo $config['SiteGlobalPath']; ?>setsession.php", {lat:x, lon:y}).done(function (data){
window.location.href="<?php echo $config['SiteGlobalPath']; ?>";});
};
navigator.geolocation.getCurrentPosition(geoSuccess);
};
</script>
how to know if the customer didn't click on the share location. and instead clicked on the block or close button ( so I could buil another query instead using their location).
Thanks in advance
You can specify a second optional function to be called when an error occours or the user denies the location request.
var geoError = function(code, message) {
alert(code + message);
};
navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
More details can be found at https://developer.mozilla.org/en-US/docs/Web/API/PositionError