problema di passaggio parametri

  • Creatore Discussione Creatore Discussione serino
  • Data di inizio Data di inizio

serino

Nuovo Utente
3 Ott 2013
2
0
0
Salve,

ho il seguente codice che mi permette di fare la conversione ; da indirizzi a coordinate.
Gli indirizzi sono scritti nella variabile:
HTML:
var addresses=["Roma", "Napoli", "Salerno", " Napoli via toledo"];

HTML:
 <script type="text/javascript">
    //<![CDATA[
    

    // delay between geocode requests - at the time of writing, 100 miliseconds seems to work well
    var delay = 100;


    if (GBrowserIsCompatible()) { 

      
      // ====== Create a Client Geocoder ======
      var geo = new GClientGeocoder(); 

      // ====== Array for decoding the failure codes ======
      var reasons=[];
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
      reasons[403]                      = "Error 403: Probably an incorrect error caused by a bug in the handling of invalid JSON.";
      
      // ====== Geocoding ======
      function getAddress(search, next) {
        geo.getLocations(search, function (result)
          { 
            // If that was successful
            if (result.Status.code == G_GEO_SUCCESS) {
              // Lets assume that the first marker is the one we want
              var p = result.Placemark[0].Point.coordinates;
              var lat=p[1];
              var lng=p[0];
              // Display the results in XML format
              var xml = '&nbsp;&nbsp;&lt;marker address="' + search + '" lat="' +lat+ '" lng="' +lng+ '"&gt;<br>';
              document.getElementById("message").innerHTML += xml;
            }
            // ====== Decode the error status ======
            else {
              // === if we were sending the requests to fast, try this one again and increase the delay
              if (result.Status.code == G_GEO_TOO_MANY_QUERIES) {
                nextAddress--;
                delay++;
              } else {
                var reason="Code "+result.Status.code;
                if (reasons[result.Status.code]) {
                  reason = reasons[result.Status.code]
                } 
                var xml = '&nbsp;&nbsp;&lt;marker address="' + search + '" error="' +reason+ '"&gt;<br>';
                document.getElementById("message").innerHTML += xml;
              }   
            }
            next();
          }
        );
      }



      // ======= An array of locations that we want to Geocode ========
     
 

var addresses=["Roma", "Napoli", "Salerno", " Napoli via toledo"];

	

      // ======= Global variable to remind us what to do next
      var nextAddress = 0;

      // ======= Function to call the next Geocode operation when the reply comes back

      function theNext() {
        if (nextAddress < addresses.length) {
          setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay);
          nextAddress++;
        } else {
          document.getElementById("message").innerHTML += "&lt;/markers&gt;";
        }
      }

      // ======= Call that function for the first time =======
      theNext();
  


    }
    
    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }

    // This Javascript is based on code provided by the
    // Community Church Javascript Team
    // http://www.bisphamchurch.org.uk/   
    // http://econym.org.uk/gmap/

    //]]>

Ora vorrei tramite questa funzione prendermi i luoghi da un database e metterli in questa variabile :

HTML:
var addresses=["Roma", "Napoli", "Salerno", " Napoli via toledo"];

Ecco il codice per far prendere da databese i luoghi:
HTML:
   // Read the data from example.xml
      downloadUrl("database.php", function(doc) {
        var xmlDoc = xmlParse(doc);
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          // obtain the attribues of each marker
		  
          var lat = parseFloat(markers[i].getAttribute("lat"));
          var lng = parseFloat(markers[i].getAttribute("lng"));
          var point = new google.maps.LatLng(lat,lng);
		  var name = markers[i].getAttribute("name");
          var luogo = markers[i].getAttribute("luogo");
          var indirizzo = markers[i].getAttribute("indirizzo");
		  var context = markers[i].getAttribute("context");
		  var data = markers[i].getAttribute("data");
		  var text = markers[i].getAttribute("text");
		  //document.write(markers.length);
          // create the marker
		 // var j=["name:"+"'"+name+"'"+","+"luogo:"+"'"+luogo+"'"+","+"indirizzo:"+"'"+indirizzo+"'"+"," + "lat:"+lat+ ","+"lng:"+lng+"," +"data:" +"'"+data+"'"+","+"context:"+"'"+context+"'"];
         //var ja=[name+","+luogo+","+indirizzo+","+lat+","+lng+","+data+context];
		 //document.write(ja);
		 var addresess = [];
		var j={};
		//j.name = name;
		j.luogo=luogo;
		j.indirizzo=indirizzo;
	
		addresess.push(j);
       
		 

        }


      });

Ma non mi funziona... Cosa sbaglio?
 

Discussioni simili