getDetails 结果中不存在地点描述

Place description doesn't exist on getDetails result

AutocompleteService 上使用 getPlacePredictions 函数时,每个结果都包含一个 description 字段。

例如查询"times square"时,第一个结果的description为"Times Square, Manhattan, NY, USA"。

保存这个结果的place_id后,用在PlacesService上的getDetails函数,同样的地方不包含description字段,而是一个名为 formatted_address 的字段,其中包含 "Manhattan, NY 10036, USA".

如何在使用 PlacesService 时获取使用 AutocompleteService 收到的原始描述?

这是因为每个服务都有不同的响应,getPlacePredictions 将 return 个预测,每个预测都有一个 description.the 描述字段,只告诉您匹配的预测是什么。

当您使用 getDetails 时,您会得到格式化的地址,它应该比描述更准确,您还可以通过 address_components 迭代 long_name 字段来构建您想要的地址格式。

对于您的查询,您实际上可以在 "name" 字段下的响应中看到 "Times Square" 和 "formated_address":Manhattan, NY 10036, USA。这是您请求的此 PLACE 详细信息的实际地址。

所以也许您只需要考虑 placeDetails 响应中的这个 "name" 字段。

如果您确实需要 "description" 的值,您可以将其保存在一个变量中并在需要时使用它