1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| function boutiqueProche(cLat, cLong,where, callback){
var geocoder= new google.maps.Geocoder();
var currentPosition = new google.maps.LatLng(cLat, cLong); // On récupère nos info
var recup = getBoutique.length;
var distance;
geocoder.geocode({ 'address': where}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var laBoutique = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());
//alert(laBoutique);
distance = google.maps.geometry.spherical.computeDistanceBetween(currentPosition, laBoutique); //récupère la distance entre ma position et l'adresse
recup=distance/1000; // On le met en Km
}
else{
if( status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT){
setTimeout( function(){
boutiqueProche(cLat, cLong, where); // rappel fonction avec meme param
}, 200);
}
else { /*Faire quelque chose */ }
}
});
return recup;
} |