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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| /*
* Geocoding
*/
(document.getElementById("search_frm").onsubmit=function(e){
geocoder.geocode({"address":document.getElementById("addr").value}, function(data, status){
if (status == google.maps.GeocoderStatus.OK) {
document.getElementById("addr").value=data[0].formatted_address;
refreshMap(data[0].geometry.location);
// Prépare la liste des suggestions
if (data.length > 1) {
var list=document.getElementById("list");
while (list.hasChildNodes()) {
list.removeChild(list.firstChild);
}
for (var i=0; i<data.length; i++) {
var a = document.createElement("a");
a.setAttribute("href", "");
a.setAttribute("title", data[i].formatted_address);
a.onclick=function(){
document.getElementById("addr").value=this.getAttribute("title");
document.getElementById("search_frm").onsubmit(false);
return false;
}
a.appendChild(document.createTextNode(data[i].formatted_address));
var li = document.createElement("li");
li.appendChild(a);
list.appendChild(li);
}
document.getElementById("suggest").style.display="block";
} else if (e !== false) { // passer FALSE au lieu d'un Event n'efface pas les suggestions
document.getElementById("suggest").style.display="none";
}
} else {
alert("Erreur: "+status);
}
});
return false;
})();
/*
* Reverse geocoding
*/
document.getElementById("reverse_frm").onsubmit=function(){
var point = new google.maps.LatLng(document.getElementById("lat").value, document.getElementById("lng").value);
geocoder.geocode({"latLng": point}, function(data, status) {
if (status == google.maps.GeocoderStatus.OK && data[0]) {
document.getElementById("addr").value=data[0].formatted_address;
refreshMap(point);
} else {
alert("Erreur: " + status);
}
});
return false;
}
/*
* Drag & drop du marqueur
*/
google.maps.event.addListener(symbole,"dragend",function(e){
refreshMap(e.latLng);
geocoder.geocode({"latLng": e.latLng}, function(data, status) {
if (status == google.maps.GeocoderStatus.OK && data[0]) {
document.getElementById("addr").value=data=data[0].formatted_address;
}
});
});
/*
* Actualise l'affichage
*/
function refreshMap(point) {
var b=Math.pow(10,decimals);
document.getElementById("lat").value=Math.round(point.lat()*b)/b;
document.getElementById("lng").value=Math.round(point.lng()*b)/b;
map.setCenter(point);
symbole.setPosition(point);
symbole.setTitle(point.lat()+";"+point.lng());
} |
Partager