我正在进行以下查询(省略key
param):
curl -v 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Helloo&types=geocode'
在我得到的结果中,第一个预测是:
{
"description" : "Clinton, New York, NY, United States",
"id" : "e5c6298aafa5b208354b16aecd163ac85eda40ae",
"matched_substrings" : [
{
"length" : 7,
"offset" : 0
}
],
"place_id" : "ChIJUWBgpFBYwokRAprvYGCydhk",
"reference" : "CkQ8AAAAKW4NgbXbTCXL8MuOOUohazn6TzvRlt8eurqW4QPFCMQXDZDP7nUQXT3c2rb4BYTcIc6fdZH2sQOj-MdNifcsZhIQFK85n69ce3b1Ec93MNxpBBoU4O778Tm2b8-tHTyCiUAZmh00QBI",
"structured_formatting" : {
"main_text" : "Clinton",
"main_text_matched_substrings" : [
{
"length" : 7,
"offset" : 0
}
],
"secondary_text" : "New York, NY, United States"
},
"terms" : [
{
"offset" : 0,
"value" : "Clinton"
},
{
"offset" : 9,
"value" : "New York"
},
{
"offset" : 19,
"value" : "NY"
},
{
"offset" : 23,
"value" : "United States"
}
],
"types" : [ "neighborhood", "political", "geocode" ]
},
你会注意到"克林顿"没有出现在我的输入字符串中。这个结果来自哪里?我为什么要这样做? matched_subtrings
包含具有偏移值和长度的数组。这些描述了输入的术语在预测结果文本中的位置,以便在需要时可以突出显示术语。
这显然不是这种情况。
答案 0 :(得分:0)
你一定搞乱了,你的请求实际上没有返回那些预测,它会返回2个与你的输入匹配的地理编码:
"predictions" : [
{
"description" : "Helloo Creek, Halls Creek, New South Wales, Australia",
"matched_substrings" : [
{
"length" : 6,
"offset" : 0
}
],
"place_id" : "ChIJWVba98sSoGsRZDAiQHlxv6I",
...
},
{
"description" : "Helloop, Achtmaal, Netherlands",
"id" : "5f9eb5caffb95c218e8c9ef002aabf7ae85d597e",
"matched_substrings" : [
{
"length" : 6,
"offset" : 0
}
],
"place_id" : "ChIJQdEGANsaxEcRUJeH7LZlmBk",
...
如果您再次遇到类似问题,请提交错误here。