Google Maps API autocomplete inconsistency in country names - google-maps

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?

Related

Google maps city search

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.

Google maps geocode does not give results

7-A Artsan Towers Trichy Road,Ramanathapuram, Coimbatore Tamil Nadu
This is what I have typed in google maps, and it gives me 5 results.
But when I give the same address in geocode api, it gives me zero results.
How should I handle this, I would like to have nearest lat long
https://maps.googleapis.com/maps/api/geocode/json?address=7-A%20Artsan%20Towers%20Trichy%20Road,Ramanathapuram,%20Coimbatore%20Tamil%20Nadu&postal_code=641045&key=keyIsHere
Result is
{"results"=>[], "status"=>"ZERO_RESULTS"}
Here you should avoid flat number, floor numbers and business names.
For more info read this
It's worked for me https://maps.googleapis.com/maps/api/geocode/json?address=7A,Artsan%20Towers%20Trich%20Road,Ramanathapuram,Coimbatore%20Tamil%20Nadu&postal_code=641045&key=Your_KEY
Result:
{ "results" : [
{
"address_components" : [
{
"long_name" : "Artsan Towers",
"short_name" : "Artsan Towers",
"types" : [ "premise" ]
},
{
"long_name" : "4",
"short_name" : "4",
"types" : [ "street_number" ]
},
{
"long_name" : "Trichy Road",
"short_name" : "Trichy Rd",
"types" : [ "route" ]
},
{
"long_name" : "Near Ramanathapuram Signal, Behind SS Palamuthir Nilayam",
"short_name" : "Near Ramanathapuram Signal, Behind SS Palamuthir Nilayam",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Ramasamy Nagar",
"short_name" : "Ramasamy Nagar",
"types" : [ "political", "sublocality", "sublocality_level_2" ]
},
{
"long_name" : "Ramanathapuram",
"short_name" : "Ramanathapuram",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "Coimbatore",
"short_name" : "Coimbatore",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Coimbatore",
"short_name" : "Coimbatore",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
},
{
"long_name" : "641045",
"short_name" : "641045",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Artsan Towers, 4, Trichy Rd, Near Ramanathapuram Signal, Behind SS Palamuthir Nilayam, Ramasamy Nagar, Ramanathapuram, Coimbatore, Tamil Nadu 641045, India",
"geometry" : {
"location" : {
"lat" : 10.9974156,
"lng" : 76.9949293
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 10.9987645802915,
"lng" : 76.99627828029151
},
"southwest" : {
"lat" : 10.9960666197085,
"lng" : 76.9935803197085
}
}
},
"partial_match" : true,
"place_id" : "ChIJEVWhlsNZqDsR4AxMyrJZQPM",
"types" : [ "street_address" ]
} ], "status" : "OK"}

MySQL: filter by value in a JSON string?

I'm trying to implement a query that computes the distance between two pairs of lat/lgn. Assume that my lat/lng values are in a JSON string, would such a query be possible (I'm assuming some string functions might be needed first to extract lat/lng)? And if possible, is it a good idea to do it? Will it scale? Or am I better off having separate columns in the database specifically for lat/lng values?
Example JSON:
{
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Parkway",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.4220352,
"lng" : -122.0841244
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.42338418029149,
"lng" : -122.0827754197085
},
"southwest" : {
"lat" : 37.4206862197085,
"lng" : -122.0854733802915
}
}
},
"place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}

How do I obtain shape of a road represented by a PlaceId

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.

Japanese characters in my JSON Google Maps API Results?

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, サン・ホセ=サニーベール=サンタ・クララ",