Pan*_*nda 8 json google-places-api
我需要获得城市名称的唯一标识符,当再次在另一种语言API中寻找同一城市时,才能找到这个地方同一个城市.
例:
我通过Google API自动填充位置进行搜索,如下所示:
城市:纽约
结果是:
纽约,纽约,美国国家代码:美国
例如,当我用俄语再次搜索"纽约"时,我需要一个纽约的唯一标识符才能知道纽约的英语与俄语相同"Нью-Йорк"
结果是:
Нью-Йорк,Нью-Йорк,СШАКодстраны:США
我的问题是如何确定两个搜索中的"纽约市"是相同的,因为我用不同语言比较同一城市的结果并确定两个答案指的是同一个纽约市?
请考虑以下两个查询.
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=newyork&types=(cities)&language=en&sensor=true&key=<YOUR-API-KEY>
Run Code Online (Sandbox Code Playgroud)
以下是JSON中响应的第一行.如您所见id,结果中有可用的reference值(值被编辑):
{
"predictions" : [
{
"description" : "New York, NY, United States",
"id" : "7eae6a016a9c6f58e2044573fb8f14227b6e1f96",
"matched_substrings" : [
{
"length" : 8,
"offset" : 0
}
],
"reference" : "CkQzAAAAs[...]g5OK5Y",
...
Run Code Online (Sandbox Code Playgroud)
现在查询俄语:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=???-????&types=(cities)&language=ru&sensor=true&key=<YOUR-API-KEY>
Run Code Online (Sandbox Code Playgroud)
此查询返回更多预测(密苏里州,内布拉斯加州等地的同名城市),但您仍然可以使用以下命令从俄语结果中找到纽约市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",
...
Run Code Online (Sandbox Code Playgroud)
您可以使用(对于上面的每个预测结果不同)查询Place Details APIreference:
https://maps.googleapis.com/maps/api/place/details/json?reference=CkRAAAAA[...]cLKfOc_4mvY&language=ru&sensor=true&key=<YOUR-API-KEY>
Run Code Online (Sandbox Code Playgroud)
并用于id验证您要搜索的地点的身份.引用地点详细信息API 文档:
id包含表示此地点的唯一稳定标识符.此标识符不能用于检索有关此地点的信息,但可用于合并有关此地方的数据,并在单独搜索中验证地点的身份.由于ids偶尔可以更改,因此建议将存储id的Place与id之后返回的相同Place的Details请求进行比较,并在必要时进行更新.
id仍然可以传递此查询,但这reference是必填字段:
https://maps.googleapis.com/maps/api/place/details/json?id=7eae6a016a9c6f58e2044573fb8f14227b6e1f96&language=ru&reference=CkRAAAAA[...]cLKfOc_4mvY&sensor=true&key=<YOUR-API-KEY>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2687 次 |
| 最近记录: |