Google Maps e ricerca indirizzi

In questo Forum potrete chiedere consigli (ma anche condividere le vostre conoscenze) sulla progettazione e realizzazione di siti. Scoprite con le nostre Muse i segreti del web design... e perché nessuno va a vedere quella paginetta che vi è costata tanta fatica. Html, xhtml, xml, css, php, asp, js, flash e tutto quel che ci gira attorno.

Moderatori: Supervisor, Moderatori Software e Programmazione

Avatar utente
Crono
Semidio
Semidio
Messaggi: 224
Iscritto il: 24 mar 2005 13:12

Google Maps e ricerca indirizzi

Messaggio da Crono »

Utilizzando le Google Maps API devo costruire una mappa che includa alcune semplici funzioni, finora quello che sono riuscito a produrre è questo:

Codice: Seleziona tutto

<!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" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <style type="text/css">
      v\:* {
        behavior:url(#default#VML);
      }
    </style>
    <script src="http://maps.google.com/maps?file=api&amp&v=2.x&key=ABQIAAAAtOjLpIVcO8im8KJFR8pcMhQjskl1-YgiA_BGX2yRrf7htVrbmBTWZt39_v1rJ4xxwZZCEomegYBo1w"
            type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[

    var map = null;
    var geocoder = null;

    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
        map.addControl(new GScaleControl());
        map.setCenter(new GLatLng(41.899344, 12.493110), 16);
        map.enableDoubleClickZoom();
        map.enableScrollWheelZoom();
        geocoder = new GClientGeocoder();
        window.setTimeout(setupOfficeMarkers, 0);
      }
    }

    function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }

    //]]>
    </script>
  </head>
  <meta content="MSHTML 6.00.6000.16481" name=GENERATOR>
  <body onload="load()" onunload="GUnload()">
    <form action="#" onsubmit="showAddress(this.address.value); return false">
      <p>
        <input type="text" size="60" name="address" />
        <input type="submit" value="Go!" />
      </p>
      <div id="map" style="width: 1000px; height: 800px"></div>
    </form>
  </body>
</html>
il problema è che non funziona la ricerca degli indirizzi ma non riesco a capire perchè visto che ha funzionato perfettamente fino a quando non ho inserito i controlli ed abilitato gli zoom, ho il sospetto che il problema sia legato a questa linea di codice "geocoder = new GClientGeocoder();" nella funzione load() ma è la prima volta che uso le API di maps e non so come risolvere

Torna a “Linguaggi per Internet”