javascript - extract province from location using google api -
i'm trying extract information location using google map api. take , it's possible don't understand i've put bounds parameter. request:
var address = document.getelementbyid("address").value; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { alert(results[0].formatted_address); } else { alert("geocode not successful following reason: " + status); } });
i suppose add bound after 'address':address not clear how. tryied doesn't works:
geocoder.geocode( { 'address': address, "types":["sublocality","political"]}, function(results, status) {
i don't know if have familiar italian province need that:
request: venezia
response: ve or venezia
request: murano
response: ve or venezia
---- improved:
using http://maps.googleapis.com/maps/api/geocode/json?address=murano&sensor=false can obtain this:
{ "results" : [ { "address_components" : [ { "long_name" : "murano", "short_name" : "murano", "types" : [ "natural_feature" ] }, { "long_name" : "venezia", "short_name" : "venezia", "types" : [ "locality", "political" ] }, { "long_name" : "venezia", "short_name" : "ve", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "veneto", "short_name" : "veneto", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "italia", "short_name" : "it", "types" : [ "country", "political" ] }, { "long_name" : "30141", "short_name" : "30141", "types" : [ "postal_code" ] } ],
trying print using alert(results[0].address_components); doesn't show me anything, how can extract this:
"long_name" : "venezia", "short_name" : "ve", "types" : [ "administrative_area_level_2", "political" ]
thanks, andrea
i not see other solution iterate address_components
, match first data short_name
contains 2 letters.
var len = results[0].address_components.length; var data; ( var = 0; < len; i++ ) { if ( results[0].address_components[i].short_name.length == 2 ) { data = results[0].address_components[i]; break; } }
Comments
Post a Comment