I need to get a unique identifier for the name of a city when that same city is again sought in another language API to find this place same city.
Example:
I do a search via the Google API Autocomplete place like this:
City: New York
The result is:
New York, NY, USA Country code: U.S.
And when I do another search for "New York" in Russian, for example, I need a unique identifier for New York to know that New York is the same in English as in Russian "Нью-Йорк"
The results is:
Нью-Йорк, Нью-Йорк, США Код страны: США
My question is how do I identify that "New York City" is the same in both searches, as I compare the results from the same city in different language and identify the two answers refer to the same New York City?
Consider the following two queries.
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=newyork&types=(cities)&language=en&sensor=true&key=<YOUR-API-KEY>
Here are few first lines of the response in JSON. As you see there is an id
available in the result (reference
values are redacted):
{
"predictions" : [
{
"description" : "New York, NY, United States",
"id" : "7eae6a016a9c6f58e2044573fb8f14227b6e1f96",
"matched_substrings" : [
{
"length" : 8,
"offset" : 0
}
],
"reference" : "CkQzAAAAs[...]g5OK5Y",
...
Now the query for Russian:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Нью-Йорк&types=(cities)&language=ru&sensor=true&key=<YOUR-API-KEY>
This query returns few more predictions (cities with the same name in Missouri, Nebraska, etc.), but still you can find New York City from the Russian results using the id
:
{
"predictions" : [
{
"description" : "Нью-Йорк, Соединенные Штаты Америки",
"id" : "7eae6a016a9c6f58e2044573fb8f14227b6e1f96",
"matched_substrings" : [
{
"length" : 8,
"offset" : 0
}
],
"reference" : "CmRZAAAA[...]s10LLA",
...
{
"description" : "Нью Йорк, Миссури, Соединенные Штаты Америки",
"id" : "211cae70217210a77581fd2a2dca45bc4286e064",
...
"reference" : "CnRpAAAA[...]FUydA",
...
{
"description" : "Нью Йорк, Небраска, Соединенные Штаты Америки",
"id" : "10a97689b3441120410e18c71d7f1b9ed70ac2e7",
...
"reference" : "CnRrAAAA[...]XrkzYY",
...
{
"description" : "Нью-Йорк Милс, Нью-Йорк, Соединенные Штаты Америки",
"id" : "2902d4dc0e1ecfe52aef4da6d5eb06e4c9fab4d9",
...
"reference" : "CoQBcwAAA[...]g3G1Jw",
...
And you can query the Place Details API using the reference
(which is different for each of the prediction results above):
https://maps.googleapis.com/maps/api/place/details/json?reference=CkRAAAAA[...]cLKfOc_4mvY&language=ru&sensor=true&key=<YOUR-API-KEY>
And use id
to verify the identity of the place you are searching for. Quoting Place Details API documentation:
id
contains a unique stable identifier denoting this place. This identifier may not be used to retrieve information about this place, but can be used to consolidate data about this Place, and to verify the identity of a Place across separate searches. Asids
can occasionally change, it's recommended that the storedid
for a Place be compared with theid
returned in later Details requests for the same Place, and updated if necessary.
Passing id
to this query is still possible, but reference
is a required field:
https://maps.googleapis.com/maps/api/place/details/json?id=7eae6a016a9c6f58e2044573fb8f14227b6e1f96&language=ru&reference=CkRAAAAA[...]cLKfOc_4mvY&sensor=true&key=<YOUR-API-KEY>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With