Google Place Details API 中的语言不一致 [英] Inconsistent language in Google Place Details API

查看:18
本文介绍了Google Place Details API 中的语言不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上使用 Google Place Details API 来存储有关地点的信息,使用客户端发送的 placeId.

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:

  • 地点 id ChIJ53USP0nBhkcRjQ50xhPN_zw 是米兰市,API 返回 Milan 作为地方,Lombardy 作为行政区域(英文名称)

  • The place id ChIJ53USP0nBhkcRjQ50xhPN_zw is the city of Milan, and the API returns Milan as locality and Lombardy as administrative area (English names)

地点id EjBWaWEgZGVsbGEgU3BpZ2EsIE1pbGFuLCBQcm92aW5jZSBvZiBNaWxhbiwgSXRhbHk是米兰的一条街道,API返回Milano作为locality and

The place id EjBWaWEgZGVsbGEgU3BpZ2EsIE1pbGFuLCBQcm92aW5jZSBvZiBNaWxhbiwgSXRhbHk is a street in Milan, and the API returns Milano as locality and Lombardia as administrative area (Italian names)

更奇怪的是,两个搜索都将Italy 返回为国家/地区.这是 API 的预期行为吗?

To make it even weirder, both searches return Italy as country. Is this the expected behavior of the API?

推荐答案

这是 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.

案例 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.

情况 2:

  • Via della Spiga:因为它是一条街道.目前,结果仅以意大利语提供,因为它们最有可能以意大利语输入.
  • 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.

当您在 Google 地图中搜索 Via della Spiga" 时的结果:

Result when you search "Via della Spiga" in Google Map:

要了解更多信息:

  1. 将地点信息翻译成指定语言根据要求.在这种情况下,要求一个功能的请求告诉开发人员结果是哪种语言,以便他们可以相应地处理数据,我个人认为这会很好,直到问题没有得到解决.

  1. 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.

语言参数位置/详细信息请求不工作

以上两个问题都是2岁左右.但是,Google 无法解决此问题.

Both of the above issues are about 2 year old. Yet, Google is unable to resolve this issues.

可能解决此问题的一种方法是使用 textsearch:

因为您可以使用文本搜索将大部分行政区域/城市转换为任何语言名称:

`https://maps.googleapis.com/maps/api/place/textsearch/json?query=Lombardia&lang‌​uage=Your_language&key=YOUR_API_KEY` 

示例:将Lombardia" 转换为中文:

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 中文是意大利伦巴第

当您搜索 placeID 详细信息时,您会得到 address_components 数组:

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" ]
         }
      ]

因此,如果您循环上述数组并使用textsearch,那么您将获得几乎一致的特定语言地址.

So if you loop over the above array and use textsearch then you will get almost consistent address in a particular language.

这篇关于Google Place Details API 中的语言不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆