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
|
<html>
<?php
//(1) On inclut la classe de Google Maps pour générer ensuite la carte.
require('GoogleMapAPI.class.php');
//(2) On crée une nouvelle carte; Ici, notre carte sera $map.
$map = new GoogleMapAPI('map');
//(3) On ajoute la clef de Google Maps.
$map->setAPIKey('AIzaSyDlpppekQpuD_AYZXvUNEqD4UcuPH-Yrto');
$map->enableMapControls();
$map->setControlSize('small');
$map->setWidth("430px");
$map->setHeight("300px");
?>
<script type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
function load($location) {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GOverviewMapControl());
geocoder = new GClientGeocoder();
showAddress($location)
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 15);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
);
}
}
//]]>
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Ma première carte Google Maps</title>
<?php $map->printHeaderJS(); ?>
<?php $map->printMapJS();
?>
</head>
<body onload="load('chine');">
<?php $map->printMap(); ?>
</body>
</html> |
Partager