JDN Développeurs > Client Web > Utiliser l'API Google Maps

Utiliser l'API Google Maps > Premières cartes, les sources

Précédente Utiliser XML 

La carte la plus simple possible :

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.   <head>
  4.     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  5.     <title>Première carte</title>
  6.     <script src="http://maps.google.com/maps?file=api&v=2&key=VOTRE_CLEF_GOOGLE_MAPS"
  7.             type="text/javascript"></script>
  8.     <script type="text/javascript">
  9.     //<![CDATA[
  10.  
  11.     function load() {
  12.       if (GBrowserIsCompatible()) {
  13.         var map = new GMap2(document.getElementById("map"));
  14.         map.setCenter(new GLatLng(48.9, 2.3), 7);
  15.       }
  16.     }
  17.  
  18.     //]]>
  19.     </script>
  20.   </head>
  21.   <body onload="load()" onunload="GUnload()">
  22.     <div id="map" style="width: 600px; height: 200px"></div>
  23.   </body>
  24. </html>

La même carte, avec zoom et recherche d'adresse :

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.   <head>
  4.     <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  5.     <title>Deuxième carte</title>
  6.     <script src="http://maps.google.com/maps?file=api&v=2&key=VOTRE_CLEF_GOOGLE_MAPS" type="text/javascript"></script>
  7.     <script type="text/javascript">
  8.     //<![CDATA[
  9.  
  10.     var map = null;
  11.     var geocoder = null;
  12.  
  13.     function load() {
  14.       if (GBrowserIsCompatible()) {
  15.         map = new GMap2(document.getElementById("map"));
  16.         map.setCenter(new GLatLng(48.9, 2.3), 7);
  17.         map.addControl(new GSmallMapControl());
  18.         map.addControl(new GMapTypeControl());
  19.         geocoder = new GClientGeocoder();
  20.       }
  21.     }
  22.  
  23.     function afficherAdresse(address) {
  24.       if (geocoder) {
  25.         geocoder.getLatLng(
  26.           address,
  27.           function(point) {
  28.             if (!point) {
  29.               alert(address + " introuvable");
  30.             } else {
  31.               map.setCenter(point, 13);
  32.               var marker = new GMarker(point);
  33.               map.addOverlay(marker);
  34.               marker.openInfoWindowHtml(address);
  35.             }
  36.           }
  37.         );
  38.       }
  39.     }
  40.     //]]>
  41.     </script>
  42.   </head>
  43.  
  44.   <body onload="load()" onunload="GUnload()">
  45.     <form action="#" onsubmit="afficherAdresse(this.address.value); return false">
  46.       <p>
  47.         <input type="text" size="88" name="address" value="70 avenue Pierre Grenier, Boulogne-Billancourt, France" />
  48.         <input type="submit" value="Go!" />
  49.       </p>
  50.       <div id="map" style="width: 600px; height: 200px"></div>
  51.     </form>
  52.   </body>
  53. </html>
Précédente Retour au sommaire Page suivante 
Introduction | Pré-requis | Premières cartes | Utiliser XML | Aller plus loin...
 
|
Haut de page
Nos autres sites Société | Mentions légales | Contacts | Publicité | PA Emploi | Presse | Recrutement | Tous nos sites | Données personnelles
© Benchmark Group, 69/71 avenue Pierre Grenier. 92517 Boulogne Billancourt Cedex