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
| <html>
<head>
<script src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var map;
var markersArray = [];
var MonTableau =[];
var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 5,
center: new google.maps.LatLng(48.861779, 2.353769),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
//creation de la carte
map = new google.maps.Map(document.getElementById('map_canvas', mapOptions), mapOptions);
//ajout des marker
addMarker(50.634438,3.059298);
//test
MonTableau = ["lille",
"lens",
"douai"
];
for( var i = 0; i < MonTableau.length; i++){
codeAddress(MonTableau[i]);
}
//test
}
function codeAddress(adresse) {
var sAddress = adresse;
geocoder.geocode( { 'address': sAddress}, 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("Geocode was not successful for the following reason: " + status);
}
});
}
function addMarker(lat,long) {
var position = new google.maps.LatLng(lat,long)
marker = new google.maps.Marker({
position: position,
map: map
});
markersArray.push(marker);
}
// Removes the overlays from the map, but keeps them in the array
function clearOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
}
}
// Shows any overlays currently in the array
function showOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(map);
}
}
}
// Deletes all markers in the array by removing references to them
function deleteOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map_canvas" style="width: 100%; height: 300px"></div>
</body>
</html> |
Partager