javascript - 谷歌地图 API JSON 响应各不相同
问题描述
当用户在输入框中键入时,我正在使用 Google 的“地点”API 来检索城镇/城市名称。我看到一些非常奇怪的行为,有时该地点的 id 将存储在 key 下,place_id
而其他时候则存储为placeId
. 下面是一个从 API 返回的示例对象以获得更多上下文:
"predictions" : [
{
"description" : "Sydney NSW, Australia",
"matched_substrings" : [
{
"length" : 1,
"offset" : 0
}
],
"place_id" : "ChIJP3Sa8ziYEmsRUKgyFmh9AQM",
"reference" : "ChIJP3Sa8ziYEmsRUKgyFmh9AQM",
"structured_formatting" : {
"main_text" : "Sydney",
"main_text_matched_substrings" : [
{
"length" : 1,
"offset" : 0
}
],
"secondary_text" : "NSW, Australia"
},
"terms" : [
{
"offset" : 0,
"value" : "Sydney"
},
{
"offset" : 7,
"value" : "NSW"
},
{
"offset" : 12,
"value" : "Australia"
}
],
"types" : [ "colloquial_area", "locality", "political", "geocode" ]
},
]
正如您在这种情况下所看到的,地点的 ID 存储在 key 下place_id
,如上所述,即使我查询完全相同的地点,有时也会随机更改。
有没有其他人遇到过这个?
解决方案
推荐阅读
- vb.net - VB.NET 多线程
- mysql - 如何使用来自另一个数据库的数据来选择数据?
- powershell - 用于设置 ms 访问的属性 PriorityClass 的 powershell 脚本
- batch-file - 如何使用命令提示符添加一行文本并保存?
- monaco-editor - Monaco Editor 中的类型检查
- java - 在 sqlite 文件夹中找不到 sqlite 数据库
- python-3.x - Django-rest-framework 序列化程序不会散列密码
- .net - Moq - 不能模拟类 - 不能隐式转换类型
- android - GraphQL 查询通过简单的 React Native 设置抛出“QueryKeyMaker 无法处理循环查询结构”
- lex - 打印 lex 中除最后一个字符之外的匹配字符串