Hi,

I'm *almost* there on my journey to create my Google map...
The user can search, drag the marker to the location of choice, I can
send the lat/lng via hidden fields...and thank you Rossko and Mike
Williams for all the support/patience/guidance in this work.

I have the lat/lng for a specific location and now I would like to
have the
Status code, status request, address, accuracy and country code as
well and pass them to a hidden field and then send it off to the PHP-
script.

I would like it as this example:
http://code.google.com/intl/sv/apis/maps/documentation/examples/geocoding-reverse.html

Although that the marker should be draggable and no info-window. The
info should be passed to the hidden textfields and then passed on the
PHP-script.

I tried to implement the code from the example but I do not the status-
code, request, address, accuracy and countrycode to display in the
text-fields as the lng/lat does. Why is this and what should I do
different?

As usual...any help is valuable! Thank you!

/Nimrod

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

    if (GBrowserIsCompatible()) {

    var map;
    var geo;
    var reasons=[];



    function load() {
      map = new GMap(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(20,0),2);



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

      // ====== Array for decoding the failure codes ======
      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.";
    }


    // ===== list of words to be standardized =====
    var standards = [   ["road","rd"],
                        ["street","st"],
                        ["avenue","ave"],
                        ["av","ave"],
                        ["drive","dr"],
                        ["saint","st"],
                        ["north","n"],
                        ["south","s"],
                        ["east","e"],
                        ["west","w"],
                        ["expressway","expy"],
                        ["parkway","pkwy"],
                        ["terrace","ter"],
                        ["turnpike","tpke"],
                        ["highway","hwy"],
                        ["lane","ln"]
                     ];

    // ===== convert words to standard versions =====
    function standardize(a) {
      for (var i=0; i<standards.length; i++) {
        if (a == standards[i][0])  {a = standards[i][1];}
      }
      return a;
    }

    // ===== check if two addresses are sufficiently different =====
    function different(a,b) {
      // only interested in the bit before the first comma in the
reply
      var c = b.split(",");
      b = c[0];
      // convert to lower case
      a = a.toLowerCase();
      b = b.toLowerCase();
      // remove apostrophies
      a = a.replace(/'/g ,"");
      b = b.replace(/'/g ,"");
      // replace all other punctuation with spaces
      a = a.replace(/\W/g," ");
      b = b.replace(/\W/g," ");
      // replace all multiple spaces with a single space
      a = a.replace(/\s+/g," ");
      b = b.replace(/\s+/g," ");
      // split into words
      awords = a.split(" ");
      bwords = b.split(" ");
      // perform the comparison
      var reply = false;
      for (var i=0; i<bwords.length; i++) {
        //GLog.write (standardize(awords[i])+"  "+standardize(bwords
[i]))
        if (standardize(awords[i]) != standardize(bwords[i])) {reply =
true}
      }
      //GLog.write(reply);
      return (reply);
    }


      // ====== Plot a marker after positive reponse to "did you mean"
======
      function place(lat,lng) {
        var point = new GLatLng(lat,lng);
        map.setCenter(point,14);
        var marker=(new GMarker(point, {draggable: true}));
        map.addOverlay(marker);
        marker.enableDragging();
        //Assign the lat/lng to the hidden fields when the marker is
placed on the map
        document.getElementById("lat").value = marker.getPoint().lat
();
        document.getElementById("lng").value = marker.getPoint().lng
();
        //Assign the lat/lng to the hidden fields when the marker is
moved by the user
        GEvent.addListener(marker, "drag", function(){
                                        
document.getElementById("lat").value=marker.getPoint().lat();
                                        
document.getElementById("lng").value=marker.getPoint().lng();

                                });


                                //*******NEW IMPL CODE********

                                                        function 
getAddress(overlay, latlng) {
      if (latlng != null) {
        address = latlng;
        geocoder.getLocations(latlng, showAddress);
      }
    }

                                            function showAddress(response) {
                                document.getElementById("statcode").value= 
response.Status.code;
       // '<b>orig latlng:</b>' + response.name + '<br/>' +
       // '<b>latlng:</b>' + place.Point.coordinates[1] + "," +
place.Point.coordinates[0] + '<br>' +
       // '<b>Status Code:</b>' + response.Status.code + '<br>' +
       // '<b>Status Request:</b>' + response.Status.request + '<br>'
+
       // '<b>Address:</b>' + place.address + '<br>' +
       // '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>'
+
       // '<b>Country code:</b> ' +
place.AddressDetails.Country.CountryNameCode);

    }

    //*******END NEW IMPL CODE********
                                document.getElementById("message").innerHTML = 
"";
                                }


      // ====== Geocoding ======
      function showAddress() {
        document.getElementById("lat").value = "";
        document.getElementById("lng").value = "";
        var search = document.getElementById("search").value;
        // ====== Perform the Geocoding ======
        geo.getLocations(search, function (result)
          {
            map.clearOverlays();
            if (result.Status.code == G_GEO_SUCCESS) {
              // ===== If there was more than one result, "ask did you
mean" on them all =====
              if (result.Placemark.length > 1) {
                document.getElementById("message").innerHTML = "Did
you mean:";
                // Loop through the results
                for (var i=0; i<result.Placemark.length; i++) {
                  var p = result.Placemark[i].Point.coordinates;
                  document.getElementById("message").innerHTML +=
"<br>"+(i+1)+": <a href='javascript:place(" +p[1]+","+p[0]+")'>"+
result.Placemark[i].address+"<\/a>";

                }
              }
              // ===== If there was a single marker, is the returned
address significantly different =====
              else {
                document.getElementById("message").innerHTML = "";
                if (different(search, result.Placemark[0].address)) {
                  document.getElementById("message").innerHTML = "Did
you mean: ";
                  var p = result.Placemark[0].Point.coordinates;
                  document.getElementById("message").innerHTML += "<a
href='javascript:place(" +p[1]+","+p[0]+")'>"+ result.Placemark
[0].address+"<\/a>";
                } else {
                  var p = result.Placemark[0].Point.coordinates;
                  place(p[1],p[0]);
                  document.getElementById("message").innerHTML =
"Located: "+result.Placemark[0].address;
                  //to update the hidden textfields with the lat/lng
values.
                        document.getElementById("lat").value = p[1];
                        document.getElementById("lng").value = p[0];
                        //Assign the lat/lng to the hidden fields when the
marker is moved by the user
                                                GEvent.addListener(marker, 
"drag", function(){
                                                                                
document.getElementById("lat").value=marker.getPoint().lat
();
                                                                                
document.getElementById("lng").value=marker.getPoint().lng
();
                                                                        });
                }
              }
            }
            // ====== Decode the error status ======
            else {
              var reason="Code "+result.Status.code;
              if (reasons[result.Status.code]) {
                reason = reasons[result.Status.code]
              }
              alert('Could not find "'+search+ '" ' + reason);
            }
          }
        );
      }
    }

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

    //]]>
    </script>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to