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
| function initMap() {
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(lat, lon),
zoom: 4,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
}
});
// Nous appelons la fonction ajax de jQuery
$.ajax({
// On pointe vers le fichier data_adresse.php
url : "data_adresse.php",
dataType : "json",
}).done(function(json)
{
var villes = json;
// On parcourt l'objet villes
let i=0;
let image="../image/drapeau.png";
for(ville in villes)
{
var mytext = "<div id='flightpath_div"+i+"'>test</div>";
var myinfowindow = new google.maps.InfoWindow({
content: mytext,
});
var marker = new google.maps.Marker
({
// parseFloat nous permet de transformer la latitude et la longitude en nombre décimal
position: {
lat: parseFloat(villes[ville].latitude_p),
lng: parseFloat(villes[ville].longitude_p)
},
title: villes[ville].pseudo,
infowindow: myinfowindow,
animation: google.maps.Animation.DROP,
label: villes[ville].pseudo.slice(0,2),//affiche les 2premiers caractère du pseudo sur le r
map: map
});//fin marker
google.maps.event.addListener(marker, 'click', function() {
this.infowindow.open(map, this);
});
var markerz = new google.maps.Marker
({
// parseFloat nous permet de transformer la latitude et la longitude en nombre décimal
position: {
lat: parseFloat(villes[ville].latitude_a),
lng: parseFloat(villes[ville].longitude_a)
},
title: villes[ville].pseudo,
infowindow: myinfowindow,
icon: image,
label: villes[ville].pseudo.slice(0,2),//affiche les 2premiers caractère du pseudo sur le r
map: map
});//fin marker
google.maps.event.addListener(markerz, 'click', function() {
this.infowindow.open(map, this);
});
i++;
}//fin for
});//fin fct json
}//fin initMap |
Partager