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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| <script type="text/javascript">
//<![CDATA[
var geocoder;
function load() {
geocoder = new google.maps.Geocoder();
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(46.841407,2.476044),
zoom: 6,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("phpsqlajax_genxml3.php", function (data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var address = markers[i].getAttribute("address");
var urlp2r = markers[i].getAttribute("urlp2r");
var catP = markers[i].getAttribute("catP");
var adressep2r = markers[i].getAttribute("adressep2r");
var myIcon = markers[i].getAttribute("iconPerso");
var annonceP = markers[i].getAttribute("annonceP");
var html = "<div style=\"font-family:arial;\"><img src=\""+ myIcon +"\" /><b>" + annonceP + "</b> <br/>" + adressep2r + " <br /><a href=" + urlp2r +" target=\"_top\" >Détails de cet emplacement sur parking2roues.com</a>";
//alert(myIcon);
(function(capturedHtml, icon){
geocoder.geocode({
'address': address
}, function (results, status) {
/* Si l'adresse a pu etre geolocalisee */
if (status == google.maps.GeocoderStatus.OK) {
/* Affichage du marker */
var marker = new google.maps.Marker({
map: map,
icon: icon,
position: results[0].geometry.location,
title: "mon titre"
});
bindInfoWindow(marker, map, infoWindow, capturedHtml, icon);
}
else{
// on traite l'erreur OVER_QUERY_LIMIT
if( status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT){
// relance la requete
setTimeout( function(){
load(); // rappel fonction avec meme param
}, 200);
}
else{
// affichage erreur
oElem.innerHTML = "Geocoder failed due to: " + status;
}
}
});
})(html, myIcon);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
//]]>
</script> |
Partager