Inconsistent language in Google Place Details API - google-maps

I'm using Google Place Details API on my server to store information about a place, using the placeId sent by a client.
I'm facing an issue regarding the language of the result, which differs when the place is a city or an address in that city, even when the language is specified in the query. For example:
The place id ChIJ53USP0nBhkcRjQ50xhPN_zw is the city of Milan, and the API returns Milan as locality and Lombardy as administrative area (English names)
The place id EjBWaWEgZGVsbGEgU3BpZ2EsIE1pbGFuLCBQcm92aW5jZSBvZiBNaWxhbiwgSXRhbHk is a street in Milan, and the API returns Milano as locality and Lombardia as administrative area (Italian names)
To make it even weirder, both searches return Italy as country. Is this the expected behavior of the API?

Is this the expected behavior of the API?
Yes, this is expected result. Even if you specify a language, it will return the response in that language only if there is one available, if not it will return the response in the language it was originally entered in.
Case 1:
Milan: As a Milan is city. Therefore,there are available results in almost every language. Almost all the major city through out the world have results in every language. By default, you will get result in English.
Case 2:
Via della Spiga: As it is a street. Right now, the results are only available in Italian as they were most possible entered in Italian.
Result when you search "Via della Spiga" in Google Map:
To learn more about this:
Translation of Places information into language specified by request. In this a request for a feature is asked that tells the developer in which language the results are so that they can take care of data accordingly, I personally think that would be great till the issue has not been fixed.
language parameter in place/details request not working
Both of the above issues are about 2 year old. Yet, Google is unable to resolve this issues.
One way to possibly solve this problem is by using textsearch:
As you can convert most of administrative area/city into any language name by using textsearch:
`https://maps.googleapis.com/maps/api/place/textsearch/json?query=Lombardia&lang‌​uage=Your_language&key=YOUR_API_KEY`
Example: Converting "Lombardia" into a chinese language:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=Lombardia&language=zh-CN&key=YOUR_API
{
"html_attributions" : [],
"results" : [
{
"formatted_address" : "意大利伦巴第",
"geometry" : {
"location" : {
"lat" : 45.47906709999999,
"lng" : 9.8452433
},
"viewport" : {
"northeast" : {
"lat" : 46.6351853,
"lng" : 11.4276993
},
"southwest" : {
"lat" : 44.6796491,
"lng" : 8.4978605
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "02401d0909d69ca5c69de799e193caf84acc41f9",
"name" : "伦巴第",
"place_id" : "ChIJf4M-GsNEgUcR1JMVKCIm8qY",
"reference" : "CoQBfQAAAEKCAV-1Ec-V2ZfnWsCk_elhlEXckc_k94jBYlU7k5ivhrqPlWd24aSAa5fqNTfwKKhU0wSsZFv42aMm1BrG5wEwZNGKwFqELxMEt0ye7KFfBgVtfHZbqeiBx3hEH8Iq60wwW--edqpROkBTjHrxIwisCGJwhCzKKkQ9H6FdfW_aEhAnmI0ZOFk1KGaGms4IqTOiGhRX5iErBIwnmLos4U9Ggs325MmcEA",
"types" : [ "administrative_area_level_1", "political" ]
}
],
"status" : "OK"
}
Lombardia in chinese is 意大利伦巴第
When you search for placeID details, you get address_components array:
"address_components" : [
{
"long_name" : "Via della Spiga",
"short_name" : "Via della Spiga",
"types" : [ "route" ]
},
{
"long_name" : "Milano",
"short_name" : "Milano",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Milano",
"short_name" : "MI",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Lombardia",
"short_name" : "Lombardia",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Italy",
"short_name" : "IT",
"types" : [ "country", "political" ]
}
]
So if you loop over the above array and use textsearch then you will get almost consistent address in a particular language.

I think you can use some Optional parameters to set what language you want, such that:
A Nearby Search request is an HTTP URL of the following form:
https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters
put language parameter, such that:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&language=en
For more detail, please refer here.

Related

Google Place API not showing current result when I tried to search for AnimalClinics

Initially I tried
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=19.031959,%2072.895695&radius=10000&type=school&sensor=true&key=AIzaSyCjQ03Ldxx9c55QmQ7ANGKRhEL*********s
this url and this showed right result
"rating" : 3.4,
"reference" : "ChIJSSUqsiDG5zsRyRBoSTT6WaA",
"scope" : "GOOGLE",
"types" : [ "point_of_interest", "school", "establishment" ],
"user_ratings_total" : 21,
"vicinity" : "Janardhan Krishna Karmalkar Marg, Brindavan Colony, Chembur West, Mumbai"
},
But when I tried to search for animal clinic it is showing some weird location.
My url:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=19.031959,%2072.895695&radius=10000&type=AnimalClinics&sensor=true&key=AIzaSyCjQ03Ldxx9c55QmQ7ANGKR********
result:
"name" : "Nishraj Insurance Services",
"opening_hours" : {
"open_now" : true
It is working fine only with School, Hospitals and Hotels location but I have to show the location of nearest Animal Clinics and Milk Dairy.
This behavior is working as intended because Animal Clinic is currently not supported in Place Types, you may visit the docs here to see the current supported place types.
The possible place type for you is veterinary_care
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=19.031959,%2072.895695&radius=10000&type=veterinary_care&sensor=true&Key=YOUR_API_KEY
The result would be:
rating: 3.9,
reference: "ChIJVVVVlffO5zsR9rpcrHikEzs",
scope: "GOOGLE",
types: [
"veterinary_care",
"point_of_interest",
"establishment"
],

Google place details street numbers with letters

When I do search in google's autocomplete I see correct address. Example:
Pavlichenko Street, 20b, Bila Tserkva, Kyiv Oblast, Ukraine
This address has place_id:
EjtQYXZsaWNoZW5rbyBTdHJlZXQsIDIwYiwgQmlsYSBUc2Vya3ZhLCBLeWl2IE9ibGFzdCwgVWtyYWluZSIwEi4KFAoSCVcssl0EQtNAEeDmEfl02RgXEBQqFAoSCVGxb54DQtNAEbhYfU4LYvbk
I need to get a street number which is "20b". To do so I use Place Details API:
https://maps.googleapis.com/maps/api/place/details/json?placeid=EjtQYXZsaWNoZW5rbyBTdHJlZXQsIDIwYiwgQmlsYSBUc2Vya3ZhLCBLeWl2IE9ibGFzdCwgVWtyYWluZSIwEi4KFAoSCVcssl0EQtNAEeDmEfl02RgXEBQqFAoSCVGxb54DQtNAEbhYfU4LYvbk&key=MY_KEY
And here what is in response:
"address_components" : [
{
"long_name" : "20",
"short_name" : "20",
"types" : [ "street_number" ]
},
{
"long_name" : "Pavlichenko Street",
"short_name" : "Pavlichenko Street",
"types" : [ "route" ]
},
{
"long_name" : "Bila Tserkva",
"short_name" : "Bila Tserkva",
"types" : [ "locality", "political" ]
...
But "20" is actually different house, I need "20b". Same happens to all streets with letters. Is there way to solve this problem? Thank you
The long place ID EjtQYXZsaWNoZW5rbyBTdHJlZXQsIDIwYiwgQmlsYSBUc2Vya3ZhLCBLeWl2IE9ibGFzdCwgVWtyYWluZSIwEi4KFAoSCVcssl0EQtNAEeDmEfl02RgXEBQqFAoSCVGxb54DQtNAEbhYfU4LYvbk indicates that this address is not present in Google database. They try to interpolate it to the best known position that matches your search.
Note that the existing in database addresses have a short place IDs, something like ChIJNSfioSOjpBIRSwaYW7O3LJY.
Your prediction has a following type
"types":[
"route","geocode"
]
So it looks like Google could resolve it to route level, but not to street address level.
I can suggest reporting a missing address to Google data team as explained in the documentation
https://support.google.com/maps/answer/3094088
I hope this addresses your doubt.
In case it helps someone, we use a regex to check whether a street number is of a "special" format, e.g. 3a, or even 3/24, both of which are reduced to just "3" by Google.
We use the "formatted" address as a reference check. Feel free to modify to match your needs:
parseStreetNumber(streetNumber, formatted) {
//Handle a format like 23/241 or 3a, which Google strips
const regex = new RegExp(`^([0-9a-z]+/${streetNumber}|${streetNumber}[a-z])`, 'i')
const matches = formatted.match(regex)
if (matches) {
return matches[1]
}
//Return as is
return streetNumber
}

Google Maps Distance Matrix wrong result

I am performing a request to the Google Maps Distance Matrix API to calculate the distance from one point to another. Both points are in Russia. The problem is that, in some cases, the API returns the wrong destination.
For example, I select this point on the Black sea coast, Russia.
The request to the API is
https://maps.googleapis.com/maps/api/distancematrix/json?origins=58.3941198,33.223535&destinations=44.58019749055891,38.0705451965332&mode=driving&language=ru-RU&key=
It returns
"destination_addresses" : [
"1 Chome-11 Kamifukubara, Yonago-shi, Tottori-ken 683-0004, Japan"
],...
So, Google Maps knows it is Russia, but Distance Matrix thinks it is Japan. Why?
Is there a known bug for places near the sea coast?
UPDATE
This bug was handled in issue tracker https://issuetracker.google.com/issues/35828610.
It was marked as Fixed on July 19, 2016.
Good news and bad news :)
The bad news is that the Japanese address will come up for many remote locations, as this is an on-going issue in the Geocoding API.
This has been reported in the Google Maps API issue tracker:
https://code.google.com/p/gmaps-api-issues/issues/detail?id=9683
Take a look at this comment on the issue tracker for details on how to workaround this.
The good news is that you still get the correct distances and route from Distance Matrix API and Directions API.
The problem with this Japan location is its bounds which say it is all around the world:
"formatted_address" : "1 Chome-11 Kamifukubara, Yonago-shi, Tottori-ken 683-0004, Japan",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 90,
"lng" : 180
},
"southwest" : {
"lat" : -90,
"lng" : -180
}
},
"location" : {
"lat" : 35.4426127,
"lng" : 133.3638089
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 90,
"lng" : 180
},
"southwest" : {
"lat" : -90,
"lng" : -180
}
}
},
"place_id" : "ChIJlwBC99P3VjUReuUmCg7qU_E",
"types" : [ "sublocality_level_3", "sublocality", "political" ]

How to get JSON from URL in Google App Engine Java

I want to get json from url in google app engine, can u tell me some quite simple methods to do this, thanks, sr my english not good
URL
Content:
{
"debug_info" : [],
"html_attributions" : [ "Listings by \u003ca href=\"http://www.diadiem.com/\"\u003eDiadiem.com\u003c/a\u003e" ],
"next_page_token" : "ClRMAAAAl7MjfntXhFEi33IPPcZJJ5fYfiJzIIGggr9Xc6A_sKeTrjohJntaaG1jWaGYMKiZYruuoqTVipUZFaLhpNXZbhYloN6SeS44epx3lPRdpuMSEHWJTSO2ShwXOz6bjg0xefcaFOUN9wK6NE5Dykjx-x-VLypkBMRH",
"results" : [
{
"geometry" : {
"location" : {
"lat" : 16.058660,
"lng" : 108.2191410
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "7064cb3f44db62207fc2bd83579b63ca9552e658",
"name" : "Vietcombank - Atm",
"reference" : "CnRwAAAAHU3y6j7CocExwcFq6DKtkS2SFT-0X23E7C9M7bpHk2EF04ShIX7IRNl9TwGF_APSwaKmk8XSZIGm52ajXnpKhj15i48w0BHmJR0ZamJdIAi3iJD_sExjjHkf5Lnfxq4iLroTAmQyRAoAVG7dMwVeTRIQcO_Qq9N85d96vQCtEdZjyRoUbETiZPHxkSjkbD9CVnQh6N_8yUA",
"types" : [ "establishment" ],
"vicinity" : "272 Phan Châu Trinh"
},
{
"geometry" : {
"location" : {
"lat" : 16.0602490,
"lng" : 108.21470
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "bd20b9fbd718c13ee3f6d404c3004b649130df4a",
"name" : "ATM DongA Bank",
"reference" : "CnRtAAAAP9XTDfjgtqvahglz24j2posRRCR9ry56xyAd0FX810ZeyiKWeEi4Btfnfycb23Sa6x_grdjJszB7Xf80jFBrer9kHYQHsKX2-spx9LHn_yrZxlfC7wxHOdUt9YbYMp71fzQ_SJOC9W1Hj2cHHi9g0BIQPrdWzJvelD1NDEcC49Q8eRoUE0juanyzeZHjyYbnozUGB13RySk",
"types" : [ "atm", "finance", "establishment" ],
"vicinity" : "Nguyễn Văn Linh, Da Nang"
},
Not sure if I got your question correctly, but if you are trying to parse Google's JSON response, a good and easy way to do it may be to use jQuery parseJSON function.
You can also take a look at this answered question to see sample code.
Also, not explicitly stated in the "answered question" link above - you cannot just access the json (or xml) from within your web page code even though you can use the url manually in a browser to get the json data (as it seems you have done in your post). There are various security aspects and Google will not even send the data requested that way (I believe it is call cross-site-scripting - Google it for more details). It has to go - as in the example linked above, from you web page to your server, have the server do the request to Google to get the data, have the server then post this back to your site/ web page (through AJAX or just a new page - however you are doing things on your site).
That's the sloppy and non-technical, but I wasted all day Sunday trying to get around this until I understood the issue and what I was supposed to (and had to do). This might not be what you are referring to but I think it may indeed be. If so I hope it helps. Cheers

Database Design: saving Google Maps data [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
SEE: http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false
I'm using MySQL.
Given a partial or complete address, the Google Map API will return something like this:
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Pkwy",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara",
"short_name" : "Santa Clara",
"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" ]
}
]
Assume I am developing an application wherein:
account owners can specify their location, and
search by location is supported
How should I store the address components I get from Google so that I can query for the following:
How many account owners in a particular country?
How many account owners in a particular state?
How many account owners in a particular ZIP/postal code?
etc.
One very easy way is to store individual address components in one table:
TABLE: account
- account_id (PK)
- street_number
- route
- locality
- administrative_area_level_2
- administrative_area_level_1
- country
- postal_code
I'll just leave blank whatever information Google does not provide (e.g. if account owner did not provide a street number, then the Google API also won't return the street_number). I think this would be the simplest to query. However, this data won't be normalized.
Alternatively, I could could design the database to have multiple tables, for example:
TABLE: country
- country_id (PK)
- name
TABLE: administrative_area_level_1
- administrative_area_level_1_id (PK)
- country_id (FK)
- name
... and so on
This will probably normalize the data, but might be a pain to query. Also, missing information might also cause some problems. For example, what if Google returns country and administrative_area_level_2, skipping administrative_area_level_1 (I'm not sure if this is even possible)? administrative_area_level_2 would require a administrative_area_level_1_id as its FK -- and without it, the model breaks.
Another idea might be to use a nested set or adjacency model. The data would be normalized and would probably be able to deal better with missing information.
My gut feeling is that the simplest model -- the one allowing redundant data -- is the best option for me. The data is not coming from me, it's coming from Google and I think I only need the data so I can do these search-by-location searches. Maybe I won't run into anomalies?
Any suggestions on how to model this?
Before you start worrying about how to model the data you retrieve from Google Maps, you might want to check out the terms of service first, at http://code.google.com/apis/maps/terms.html.
Particularly take note of 10.1.3 (a):
"You must not copy, translate, modify, or create a derivative work (including creating or contributing to a database) of, or publicly display any Content or any part thereof..."
I'd say that pretty much explicitly prohibits the kind of application you're trying to build. If you want to query the address information Google has about one of your account owners, you have to do it using Google's APIs - not copying their data and doing it in your own application.