I’m trying to extract some extra information from a location using google map api. I take a look and it’s possible but I don’t understand well where I’ve to put the bounds parameter. This is my 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 was not successful for the following reason: " + status);
}
});
I suppose to add the bound after ‘address’:address but not clear how. I tryied with that but it doesn’t works:
geocoder.geocode( { 'address': address, "types":["sublocality","political"]}, function(results, status) {
I don’t know if have familiar with Italian province but I need something like 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 I 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 to print using alert(results[0].address_components); it doesn’t show me anything, how can I extract this:
"long_name" : "Venezia",
"short_name" : "VE",
"types" : [ "administrative_area_level_2", "political" ]
thanks,
Andrea
I do not see any other solution than iterate by
address_componentsand match first data withshort_namethat contains 2 letters.