1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| function findAddress2(adresse, name, lt, lg) {
var lat = parseFloat(lt.replace(',','.'));
var lng = parseFloat(lg.replace(',','.'));
var latlng = new google.maps.LatLng(lat, lng);
var address = adresse;
// script uses our 'geocoder' in order to find location by address name
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) { // and, if everything is ok
// we will center map
var addrLocation = latlng;
map.setCenter(addrLocation);
// store current coordinates into hidden variables
document.getElementById('lat').value = lat;
document.getElementById('lng').value = lng;
// and then - add new custom marker and Infowindow
var addrMarker = new google.maps.Marker({
position: addrLocation,
map: map,
title: results[0].formatted_address
//animation: google.maps.Animation.BOUNCE
});
iconFile = 'https://maps.gstatic.com/mapfiles/ms2/micons/gas.png';
addrMarker.setIcon(iconFile) ;
var infowindow = new google.maps.InfoWindow({
content: '<DIV STYLE="line-height:1.35;overflow:hidden;white-space:nowrap;"><DIV STYLE=overflow:auto; width:50px; height:50px><font style="color:#000;">' + name +
'<br /></font></div></div>'
});
google.maps.event.addListener(addrMarker, 'click', function (data) {
infowindow.open(map, addrMarker);
});
markers.push(addrMarker);
addrMarker.indice = markers.length - 1;
// suppression du marker sur dblclick
google.maps.event.addListener(addrMarker, 'dblclick', function (data) {
this.setMap(null);
var ind = this.indice;
markers.splice(ind, 1);
// r?©ajuste les indices des autres marqueurs
for (; markers[ind]; ind++) {
markers[ind].indice = ind;
}
});
}
else{
// on traite l'erreur OVER_QUERY_LIMIT
if( status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT){
// relance la requete
setTimeout( function(){
findAddress2(adresse, name, lt, lg); // rappel fonction avec meme param
}, 200);
}
}
});
} |
Partager