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
| var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var paris = new google.maps.LatLng(48.8566667, 2.3509871);
var mapOptions = {
zoom: 8,
center: paris,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
/* Chargement de la carte */
map = new google.maps.Map(document.getElementById("map"), mapOptions);
}
/* Fonction de geocodage */
function codeAddressXml () {
downloadUrl('test.xml', function(data) {
var markers = data.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var address = markers[i].getAttribute("adresse");
geocoder.geocode( { 'address' : address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker (
{
map : map,
position : results[0].geometry.location
})
} else {
alert("Le geocodage pour" + address + "a echoué. " + status)
}
});
}
});
} |