We have an autocomplete field using google maps api to automatically fill in city details fields
So using "(cities)" as type we get a list of cities matching the search fine however the data is not consistent and it's large Australian cities that are missing things like postal_code field. Lookup as below
this.autocomplete = new google.maps.places.Autocomplete((this.element), { types: ["(cities)"] , componentRestrictions: {country: ["au","nz"]}});
So when searching on city such as a suburb like "Richmond" you get the following response
/**/_xdc_._n1gyyx && _xdc_._n1gyyx( {
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "Richmond",
"short_name" : "Richmond",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Yarra City",
"short_name" : "Yarra",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Victoria",
"short_name" : "VIC",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Australia",
"short_name" : "AU",
"types" : [ "country", "political" ]
},
{
"long_name" : "3121",
"short_name" : "3121",
"types" : [ "postal_code" ]
}
],
with "postal_code" and "locality", "political"
However searching on Melbourne you'd expect details with postcode 3000 however you only get
/**/_xdc_._ntt86i && _xdc_._ntt86i( {
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "Melbourne",
"short_name" : "Melbourne",
"types" : [ "colloquial_area", "locality", "political" ]
},
{
"long_name" : "Victoria",
"short_name" : "VIC",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Australia",
"short_name" : "AU",
"types" : [ "country", "political" ]
}
],
So now name is stored in "colloquial_area", "locality", "political" and there's no "postal_code"
But when filtering on Melbourne in the autocomplete all you get is that Melbourne option or Melbourne airport of which neither is correct. If you then change types to "(regions) you can search on postcode which does return the correct Melbourne version.
Has anyone encountered this and worked out a way to force the filtered results to show only versions with a postcode?
This behavior is working as intended, because places like Melbourne have multiple postal code inside its area (e.g. 3977, 3156, 3806, 3978, etc.), therefore, results will not return postal code as it is not made to handle multiple postal codes and cannot return single postal code as it will affect the integrity of the information because it will not be applicable for the rest of the postal codes.
You may file a Feature Request in the Issue Tracker to request for this kind of capability in handling multiple postal codes.
Related
I am working with Google Map API but I noticed that Google Map API and Google Map address is not showing the same address.
For example, I have the following latitude and longitude.
Lat = 3.182670
Long = 113.095663
Using Google Map API
https://maps.googleapis.com/maps/api/geocode/json?latlng=3.182670,113.095663&key=YOUR_API_KEY
I am getting this as the result
"results" : [
{
"address_components" : [
{
"long_name" : "Asian Highway 150",
"short_name" : "AH150",
"types" : [ "route" ]
},
{
"long_name" : "Bintulu",
"short_name" : "Bintulu",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Sarawak",
"short_name" : "Sarawak",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Malaysia",
"short_name" : "MY",
"types" : [ "country", "political" ]
},
{
"long_name" : "97000",
"short_name" : "97000",
"types" : [ "postal_code" ]
}
],
However when I Google Map search the same coordinates, I get the Jalan Sibiyu, 97000 Bintulu, Sarawak as the result.
https://www.google.com.my/maps/place/3%C2%B010'57.6%22N+113%C2%B005'44.4%22E/#3.18267,113.093469,17z/data=!3m1!4b1!4m5!3m4!1s0x0:0x29c434a6775850e2!8m2!3d3.18267!4d113.095663
So question is:
Why is the coordinates are the same, but I am getting differnt result?
What can I do to get the same result?
Why do I get reponse with a different place_id, then the one I used in my place details API query?
https://maps.googleapis.com/maps/api/place/details/json?placeid=Eiw5LzUwIE1hcmtldCBTdHJlZXQsIE1lbGJvdXJuZSBWSUMsIEF1c3RyYWxpYSIwEi4KFAoSCR3TztZMXdZqEREXsZzx5CRAEDIqFAoSCXUvVtBMXdZqEc9Cc6QFzzMr&fields=address_components,formatted_address,place_id,types&key=
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "50",
"short_name" : "50",
"types" : [ "street_number" ]
},
{
"long_name" : "Market Street",
"short_name" : "Market St",
"types" : [ "route" ]
},
{
"long_name" : "Melbourne",
"short_name" : "Melbourne",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Melbourne City",
"short_name" : "Melbourne",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Victoria",
"short_name" : "VIC",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Australia",
"short_name" : "AU",
"types" : [ "country", "political" ]
},
{
"long_name" : "3000",
"short_name" : "3000",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "50 Market St, Melbourne VIC 3000, Australia",
"place_id" : "Eis1MCBNYXJrZXQgU3QsIE1lbGJvdXJuZSBWSUMgMzAwMCwgQXVzdHJhbGlhIjASLgoUChIJHdPO1kxd1moRERexnPHkJEAQMioUChIJdS9W0Exd1moRz0JzpAXPMys",
"types" : [ "street_address" ]
},
"status" : "OK"
}
Also I noticed the address returned is different.
The placeid in my query, is what I received for an autocompletion service response.
{
"description" : "9/50 Market Street, Melbourne VIC, Australia",
"id" : "06f000a321dc5f1347b79dcbe4d611390f750f36",
"matched_substrings" : [
{
"length" : 18,
"offset" : 0
}
],
"place_id" : "Eiw5LzUwIE1hcmtldCBTdHJlZXQsIE1lbGJvdXJuZSBWSUMsIEF1c3RyYWxpYSIwEi4KFAoSCR3TztZMXdZqEREXsZzx5CRAEDIqFAoSCXUvVtBMXdZqEc9Cc6QFzzMr",
"reference" : "Eiw5LzUwIE1hcmtldCBTdHJlZXQsIE1lbGJvdXJuZSBWSUMsIEF1c3RyYWxpYSIwEi4KFAoSCR3TztZMXdZqEREXsZzx5CRAEDIqFAoSCXUvVtBMXdZqEc9Cc6QFzzMr",
"structured_formatting" : {
"main_text" : "9/50 Market Street",
"main_text_matched_substrings" : [
{
"length" : 18,
"offset" : 0
}
],
"secondary_text" : "Melbourne VIC, Australia"
},
"terms" : [
{
"offset" : 0,
"value" : "9/50 Market Street"
},
{
"offset" : 20,
"value" : "Melbourne"
},
{
"offset" : 30,
"value" : "VIC"
},
{
"offset" : 35,
"value" : "Australia"
}
],
"types" : [ "route", "geocode" ]
}
Looks like for some reason, google maps is dropping the subpermise information, when using the place details API and returning the street_address.
Is there a way I can force google maps API to return me the details for the subpremise?
The long place ID like Eis1MCBNYXJrZXQgU3QsIE1lbGJvdXJuZSBWSUMgMzAwMCwgQXVzdHJhbGlhIjASLgoUChIJHdPO1kxd1moRERexnPHkJEAQMioUChIJdS9W0Exd1moRz0JzpAXPMys in your example means that there is no exact street address for your search in database of Google. This is an approximation. When you search an address that exists in the database you will get shorter place ID (e.g. ChIJrTLr-GyuEmsRBfy61i59si0).
If address doesn't exists in Google database you can get one long place ID from autocomplete service and a different long place ID from the place details endpoint. These endpoints can use different algorithms for approximations that results in different place IDs for addresses that are not found in the database.
Both types of place IDs are mentioned in the documentation
https://developers.google.com/places/place-id#id-overview
The most straightforward way to fix the issue is reporting a missing address to Google data team as described in
https://support.google.com/maps/answer/6320846.
Once added in Google database your issue will disappear, you will get a short place ID both in autocomplete and in details.
Also your issue might be related to the bug reported in Google issue tracker regarding limited support of subpremises in place autocomplete service. Have a look at
https://issuetracker.google.com/issues/35830389
I hope this addresses your doubt.
I am trying to parse Google Places JSON provided when I call its API. My Problem is that I need to get address data in separate.
For example:
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "48",
"short_name" : "48",
"types" : [ "street_number" ]
},
{
"long_name" : "Pirrama Road",
"short_name" : "Pirrama Road",
"types" : [ "route" ]
},
{
"long_name" : "Pyrmont",
"short_name" : "Pyrmont",
"types" : [ "locality", "political" ]
},
{
"long_name" : "NSW",
"short_name" : "NSW",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "AU",
"short_name" : "AU",
"types" : [ "country", "political" ]
},
{
"long_name" : "2009",
"short_name" : "2009",
"types" : [ "postal_code" ]
}
], ......
I need to get the postal_code, so I could use the Jason Path $.result.address_components[5].long_name, but sometimes the Json doesn't have the street_number, or the route and in these cases, I get the wrong data or null.
What I need is a way to get the long_name where the level's type is postal_code using Xpath (because I using Pentaho to parse it and this is the way it works).
Thanks in advance.
You'll likely need a couple of JSON Input steps, one to get the individual address components (and the types inside), and one to get the long_name:
The Filter Rows step will pick the right one(s) by type, then the last JSON Input will get you the fields from the one(s) you want. Here's a Gist with your sample input:
https://gist.github.com/mattyb149/0ceea5d7e33ae86782e0
Let me know if you have any questions, issues, etc. Cheers!
In my data I have found many examples like the following. If you search Google for "Cheyney University PA", you get the following information:
Address: 1837 University Cir, Cheyney, PA 19319
Phone: (610) 399-2000
However, when doing a search using the following:
my $pid_url = Mojo::URL->new('https://maps.googleapis.com/maps/api/place/textsearch/json');
$pid_url->query({query => $query, key => 'removed'});
my $place_id = $ua->get($pid_url)->res->json->{results}->[0]->{place_id};
# Query = https://maps.googleapis.com/maps/api/place/textsearch/json?query=Cheyney+University+PA&key=removed
# Place ID returned = ChIJ5wiPkSvuxokR2rwaVUTMwks
$deets_url = Mojo::URL->new('https://maps.googleapis.com/maps/api/place/details/json');
$deets_url->query({placeid => $place_id, key => 'removed'});
say $ua->get($deets_url)->res->body;
I get the following back from Google:
{
"result" : {
"address_components" : [
{
"long_name" : "Cheyney",
"short_name" : "Cheyney",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Thornbury",
"short_name" : "Thornbury",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Delaware County",
"short_name" : "Delaware County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Pennsylvania",
"short_name" : "PA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Cheyney, PA, USA",
"name" : "Cheyney",
"place_id" : "ChIJ5wiPkSvuxokR2rwaVUTMwks",
"scope" : "GOOGLE",
"types" : [ "locality", "political" ],
"url" : "https://maps.google.com/maps/place?q=Cheyney,+PA,+USA&ftid=0x89c6ee2b918f08e7:0x4bc2cc44551abcda",
"vicinity" : "Cheyney"
},
"status" : "OK"
}
(I removed some of the output for clarity.) Notice that in the results the street address components are missing (1837 University Cir), as well as the phone number. I have found many instances like this, and I am trying to figure out why my queries are not returning the same results as what I get when I Google the information.
Here's another example:
Google Results:
Address: 1320 S Dixie Hwy, Coral Gables, FL 33124
Phone: (305) 284-2211
Places API Results:
{
"html_attributions" : [],
"results" : [
{
"formatted_address" : "University of Miami, Coral Gables, FL 33146, USA",
"geometry" : {
"location" : {
"lat" : 25.7216374,
"lng" : -80.2792843
},
"viewport" : {
"northeast" : {
"lat" : 25.7316894,
"lng" : -80.26327689999999
},
"southwest" : {
"lat" : 25.7115846,
"lng" : -80.29529169999999
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "7eb529034293a6eb760e990e034a4314d83edcf7",
"name" : "University of Miami",
"place_id" : "ChIJn9K4n_C32YgRqR37uAXB5IM",
"reference" : "CqQBnAAAACffq3Xp3JUFowUDlEsge90htrhAoUES9tGmsB919iNQCxgldtq4khP4f_gCAju90qGY1IEUH52hZl_GP_H6xJC5z22EceCfprWEHFhhXKsW23Y9EeV24svXC-PRYnOyQaXZmbQFCeUlsmKWB6570e-8W_w31muZKwFd4hVPdeeqO45zH2zp7CAuSrHjBr0bSiOQufEB59ibxG4QcuwenSASEHvq1xMcCCtMUsFcyLYsrOIaFN0vg6S680hJay1jDSrZ686Mt9Gn",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
}
],
"status" : "OK"
}
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "University of Miami",
"short_name" : "University of Miami",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Coral Gables",
"short_name" : "Coral Gables",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Miami-Dade County",
"short_name" : "Miami-Dade County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Florida",
"short_name" : "FL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "33146",
"short_name" : "33146",
"types" : [ "postal_code" ]
}
],
"adr_address" : "University of Miami, \u003cspan class=\"locality\"\u003eCoral Gables\u003c/span\u003e, \u003cspan class=\"region\"\u003eFL\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e33146\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUSA\u003c/span\u003e",
"formatted_address" : "University of Miami, Coral Gables, FL 33146, USA",
"geometry" : {
"location" : {
"lat" : 25.7216374,
"lng" : -80.2792843
},
"viewport" : {
"northeast" : {
"lat" : 25.7316894,
"lng" : -80.26327689999999
},
"southwest" : {
"lat" : 25.7115846,
"lng" : -80.29529169999999
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "7eb529034293a6eb760e990e034a4314d83edcf7",
"name" : "University of Miami",
"place_id" : "ChIJn9K4n_C32YgRqR37uAXB5IM",
"reference" : "CqQBlAAAAFeKC7LbGqAr7-LnBXMqbMIhuyuUh22XBMRO11hADojDclomC-InGocKSStmZ8S-S1UVWC1qHAsZi3XSp7PiDOFBgZVMqhm5kr87CfEAJmPdwsmZ6VEg5FxXh5LZmSSZdFgH0UR0OVGLL5M17SmWZp4W3Die8UNa5yCMyV5CP0T0VWmvqCb54qJR6mlyIx1itiLzRp1XhTs8_UmEt9pjIkYSEGrAqS6TWo2G1WBOrDO0YSAaFO4FfqvmFabJLia36vKL0XTz23Mu",
"scope" : "GOOGLE",
"types" : [ "sublocality_level_1", "sublocality", "political" ],
"url" : "https://maps.google.com/maps/place?q=University+of+Miami,+Coral+Gables,+FL+33146,+USA&ftid=0x88d9b7f09fb8d29f:0x83e4c105b8fb1da9",
"vicinity" : "University of Miami"
},
"status" : "OK"
}
It looks like you are wanting to use Google Maps to do some sort of address validation and parsing. The short story is, unfortunately Google Maps cannot be replied upon to return parsed address components consistently. What Google Maps does do really well is geocode - that is translate input into lat/long to be displayed on a map. You could perhaps try reverse geocoding (i.e. giving Google lat/long) to see what that returns, but I'm pretty sure you will get similar results.
I have also wanted and tried in vain to use Google Maps similarly in the past myself. After much testing against various international, real world datasets, I concluded that Google couldn't be used for validation any more than (a) getting lat/long (b) a general yes/no that address sort of looks ok. I have also tried some other Geocoding providers and later settled on GeocodeFarm when Google proved too expensive once my sites outgrew what they previously provided for free. My general conclusion was the same though - I had to stick to fairly traditional address data entry forms without 'fullproof' validation, otherwise users would be told addresses were faulty that were actually valid. GeocodeFarm did "pretty print" localized addresses quite well though (i.e. almost suitable for putting as a mailing label on an envelope), but it wasn't parsed into components for storage into a typical relational database schema.
Doing some more research to verify my own experiences, I found this and this to be useful. These links also point towards a service called 'SmartyStreets' - I cannot vouch for it however, and have zero experience with it.
Hope that helps!
I'm based in USA and make a call to: http://maps.googleapis.com/maps/api/geocode/json?latlng=xxx,xxx&sensor=false and see most data in english and then this. (note; xxx is actually a real lat & lng, just removed here).
Anyone know what this is and why its here? How do I get rid of irrelevant results?
{
"address_components" : [
{
"long_name" : "サン・ホセ=サニーベール=サンタ・クララ",
"short_name" : "サン・ホセ=サニーベール=サンタ・クララ",
"types" : [ "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "United States, California, サン・ホセ=サニーベール=サンタ・クララ",