After a user clicks an image (html code) I want it to ask for geolocation and only href when captured. The issue is that the specialDisplyLocation method is not being called at all to set the variables. I'm thinking it's something with the way I'm using the callback.
latlng, lat and lng are global variables
Here's the current code:
function getForSpecial(callback) {
callback (arguments[1]);
}
function getGeo (compid){
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(specialDisplayLocation, displayError);
window.location.href = "specials.php?cid="+compid+"&lat="+lat+"&lng="+lng;
}else{
display(2,"Sorry - your browser doesn't support geolocation! " +
"Use your postal code.");
}
}
function specialDisplayLocation() {
latlng = new google.maps.LatLng(
parseFloat(position.coords.latitude),
parseFloat(position.coords.longitude));
lat = position.coords.latitude;
lng = position.coords.longitude;
alert("lat: "+lat);
}
Html:
<div class="ad_125x125"
onclick="getForSpecial(getGeo,<?php echo $output125[0][0]; ?>)">
<img src="/ed/img/promos/125/<?php echo $output125[0][1]; ?>" />
</div>
As you are calling specialDisplayLocation
as success callback. I would suggest you to redirect in that method.
function specialDisplayLocation() {
latlng = new google.maps.LatLng(
parseFloat(position.coords.latitude),
parseFloat(position.coords.longitude));
lat = position.coords.latitude;
lng = position.coords.longitude;
alert("lat: "+lat);
//Redirect
window.location.href = "specials.php?cid="+compid+"&lat="+lat+"&lng="+lng;
}
Try this
function getForSpecial(callback) {
callback (arguments[1]);
}
function getGeo (compid){
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(){
specialDisplayLocation();
window.location.href = "specials.php?cid="+compid+"&lat="+lat+"&lng="+lng;
}, displayError);
}else{
display(2,"Sorry - your browser doesn't support geolocation! " +
"Use your postal code.");
}
}
function specialDisplayLocation() {
latlng = new google.maps.LatLng(
parseFloat(position.coords.latitude),
parseFloat(position.coords.longitude));
lat = position.coords.latitude;
lng = position.coords.longitude;
alert("lat: "+lat);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments