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?
Related
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.
If I have a PlaceId that represents a road, how can I obtain the shape of the road to highlight it on the map? The Places API only returns a single location in the geometry field for roads.
For example given PlaceID: ChIJ8R8rpjCuEmsRKxCMhhWn9Kg
I get the following response. Notice the types field has value of "route", but the geometry field only provides single location instead of a path.
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "Darling Dr",
"short_name" : "Darling Dr",
"types" : [ "route" ]
},
{
"long_name" : "Sydney",
"short_name" : "Sydney",
"types" : [ "locality", "political" ]
},
{
"long_name" : "New South Wales",
"short_name" : "NSW",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Australia",
"short_name" : "AU",
"types" : [ "country", "political" ]
},
{
"long_name" : "2000",
"short_name" : "2000",
"types" : [ "postal_code" ]
}
],
"adr_address" : "\u003cspan class=\"street-address\"\u003eDarling Dr\u003c/span\u003e, \u003cspan class=\"locality\"\u003eSydney\u003c/span\u003e \u003cspan class=\"region\"\u003eNSW\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e2000\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eAustralia\u003c/span\u003e",
"formatted_address" : "Darling Dr, Sydney NSW 2000, Australia",
"geometry" : {
"location" : {
"lat" : -33.8718136,
"lng" : 151.1984465
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "82a04f4f0548a2e7c467b71ed9c2a3a1615dac50",
"name" : "Darling Dr",
"place_id" : "ChIJ8R8rpjCuEmsRKxCMhhWn9Kg",
"reference" : "CpQBhAAAAA4dsRcdqFcTxsVmwWs1ZWWSg9XdclQgRHhLYT2XJwEIU8BOXoS3D4cM58oNhcND-bJU7k7nmLvgHZFep405LokQpkTu0yUPQtrrgNonLRVPdLy4j9Z0M7iBpmGkPN6BuDntYu6JG9urfnIJZRdIvpibFI9QxzP7uheEnJQtI7S8Aoxth99pVl5OvyySDSfn5hIQ4Nf4YLpRjiuY34ND9qvTyBoUr24qn9M1aFa6GoO46wrfW2a12DA",
"scope" : "GOOGLE",
"types" : [ "route" ],
"url" : "https://maps.google.com/maps/place?q=Darling+Dr,+Sydney+NSW+2000,+Australia&ftid=0x6b12ae30a62b1ff1:0xa8f4a715868c102b",
"vicinity" : "Sydney"
},
"status" : "OK"
}
This functionality is not supported. What you can do is create a map on MyMap and add a driving route for the path you want to highlight. Then, you can save it and export it as a KML layer. If you wanted to do this programmatically, you could use the Directions API to get the polyline for the route.
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!
We are making requests to Google to get the coordinates and the country for specific cities and hotels.
We are using the autocomplete and for example:
"Amsterdam, The Netherlands"
We get the location reference = CkQyAAAAWv8eQqe4JnyaX6oGHP8SIq6eGIUrN6Jx8dFsOEcDn7OCLIRR-ZxucR5jg8P-FJtm6fgFkOjhxAUfzE6JL8un5xIQcN_hKzWaS6pUVCyt5xAjghoU1jfArNwwQRbTiu_ZxwBTzlnZr9Q
We make a call again to Google to get the coordinates and the country. This is the link
https://maps.googleapis.com/maps/api/place/details/json?reference=CkQyAAAAWv8eQqe4JnyaX6oGHP8SIq6eGIUrN6Jx8dFsOEcDn7OCLIRR-ZxucR5jg8P-FJtm6fgFkOjhxAUfzE6JL8un5xIQcN_hKzWaS6pUVCyt5xAjghoU1jfArNwwQRbTiu_ZxwBTzlnZr9Q&sensor=false&key=[KEY]
We get this response
{
"long_name" : "Amsterdam",
"short_name" : "Amsterdam",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Government of Amsterdam",
"short_name" : "Government of Amsterdam",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "North Holland",
"short_name" : "NH",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "The Netherlands",
"short_name" : "NL",
"types" : [ "country", "political" ]
}
We take the country by "long_name" : "The Netherlands" and we are happy but there comes this case:
We are using autocomplete for "Hotel luxer"
We get the location reference = ClRFAAAAzuaZS1YQuJOjjO3NH2rDIDrrJyiiyvmGVF90-WdZB-_mpjROO-a322bJQHYRRGVQTySPcCmpmgHYXCH9-useDg_EeRSX1tL9Igz9e1TuYcISEELfMqkiKHE5BuR7i3Y6fMYaFMXY5fk_psERzpGHesrRJhnO5gPl
We make the call again to Google, here is the link:
https://maps.googleapis.com/maps/api/place/details/json?reference=ClRFAAAAzuaZS1YQuJOjjO3NH2rDIDrrJyiiyvmGVF90-WdZB-_mpjROO-a322bJQHYRRGVQTySPcCmpmgHYXCH9-useDg_EeRSX1tL9Igz9e1TuYcISEELfMqkiKHE5BuR7i3Y6fMYaFMXY5fk_psERzpGHesrRJhnO5gPl&sensor=false&key=[KEY]
This is the response
{
"long_name" : "11",
"short_name" : "11",
"types" : [ "street_number" ]
},
{
"long_name" : "Warmoesstraat",
"short_name" : "Warmoesstraat",
"types" : [ "route" ]
},
{
"long_name" : "Amsterdam",
"short_name" : "Amsterdam",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Netherlands",
"short_name" : "NL",
"types" : [ "country", "political" ]
},
{
"long_name" : "1012 HT",
"short_name" : "1012 HT",
"types" : [ "postal_code" ]
}
We get the "long_name" : "Netherlands", even if the original autocomplete was with "The Netherlands".
Is there any option that we can set to be sure that we get a default name for the country?
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, サン・ホセ=サニーベール=サンタ・クララ",