这里的自动完成 API 忽略了语言参数

问题描述

我不确定这是错误还是我不知道的某些预期行为,但会返回其他语言的结果,即使使用 language 参数也是如此。例如:

https://autocomplete.geocoder.ls.hereapi.com/6.2/suggest.json?resultType=cities&language=en&apiKey=_API_KEY_&query=mess

最上面的结果是:

{ 
  "label":"Messico","language":"en","countryCode":"MEX","locationId":"NT_f0csxXUfj7csl1d3kXH7yA","address": {"country":"Messico"},"matchLevel":"country"
}

Messico 在意大利语中是墨西哥,或者:

https://autocomplete.geocoder.ls.hereapi.com/6.2/suggest.json?resultType=cities&language=en&apiKey=_API_KEY_&query=al

{
  "label":"Allemagne","countryCode":"DEU","locationId":"NT_sCRfuPPAnURShDKlGtXPTB","address":{"country":"Allemagne"},"matchLevel":"country"
}

Allemagne 在法语中是德国。

当翻译不可用时,除了参数中指定的语言或本地语言之外,我不想显示带有任何其他语言标签的结果。我该怎么做?

解决方法

您应该使用参数值 resultType=city 而不是城市,如下所示,然后您会看到响应的差异。

https://autocomplete.geocoder.ls.hereapi.com/6.2/suggest.json?apiKey={API_KEY}&query=mess&resultType=city&language=en

请参阅文档,没有像城市那样的东西。 https://developer.here.com/documentation/geocoder-autocomplete/dev_guide/topics/resource-suggest.html