gmaps Address Component Types get country name

Posted by gmapsuser on Stack Overflow See other posts from Stack Overflow or by gmapsuser
Published on 2010-06-05T21:36:58Z Indexed on 2010/06/05 21:42 UTC
Read the original article Hit count: 181

Filed under:

hi .. iam trying to get the country name using the Address Component Types available from gmaps V3.

i dont know how i can get it the right way.. http://code.google.com/apis/maps/documentation/javascript/services.html#GeocodingAddressTypes

iam trying to alert the country name liks here :

alert(results[1].address_component[country]);

and here`s the code.. any help is really appreciated..thanks

  function codeLatLng() {
    var input = document.getElementById("latlng").value;
    var latlngStr = input.split(",",2);
    var lat = parseFloat(latlngStr[0]);
    var lng = parseFloat(latlngStr[1]);
    var latlng = new google.maps.LatLng(lat, lng);
    if (geocoder) {
      geocoder.geocode({'latLng': latlng}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          if (results[1]) {
          alert(results[1].address_component[country]);
          } else {
            alert("No results found");
          }
        } else {
          alert("Geocoder failed due to: " + status);
        }
      });
    }
  }

© Stack Overflow or respective owner

Related posts about google-maps