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
| <?php include 'connect.php';?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script src="http://127.0.0.1/ajax_crud_datatables_images_upload/assets/jquery/jquery-2.1.4.min.js"></script>
<script src="https://maps.google.com/maps/api/js?key=AIzaSyDrzdccScwx82cSYbNMeSzpYY4hx21S3lJ" type="text/javascript"></script>
<script async type="text/javascript">
// On initialise la latitude et la longitude (centre de la carte)
var lat = 43.3;
var lon = 5.4;
var map = null;
// Fonction d'initialisation de la carte
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(lat, lon),
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
scrollwheel: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
}
});
// Nous appelons la fonction ajax de jQuery
$.ajax({
// On pointe vers le fichier selectData.php
url : "http://localhost/ajax_crud_datatables_images_upload/selectData.php",
}).done(function(json){ // Si on obtient une réponse, elle est stockée dans la variable json
// On construit l'objet villes à partir de la variable json
var villes = JSON.parse(json);
// On parcourt l'objet villes
for(ville in villes){
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].lat), lng: parseFloat(villes[ville].lon)},
title: villes[ville].nom,
map: map
});
}
});
}
window.onload = function(){
// Fonction d'initialisation qui s'exécute lorsque le DOM est chargé
initMap();
};
</script>
<style type="text/css">
#map{ /* la carte DOIT avoir une hauteur sinon elle n'apparaît pas */
height:400px;
}
</style>
<title>Carte</title>
</head>
<body>
<div id="map">
<!-- Ici s'affichera la carte -->
</div>
</body>
</html> |
Partager