gpt4 book ai didi

google-places-api - 为什么自动完成响应中的某些信息与后续详细信息响应中返回的信息不同?

转载 作者:行者123 更新时间:2023-12-02 04:59:59 27 4
gpt4 key购买 nike

当我对“98 Spru”执行 Google Places 自动完成请求时,我得到一个具有一个 ID (013ae3e513081ff1bc9e3dc202df54ba9d147285) 和一组类型(“路线”和“地理编码”)的地点预测,但是当我获取其详细信息时放置它具有不同的 ID(5e66bbb5a5a7eaedd07fabc199e87570bcc0eae6)和一组不同的类型(“street_address”)?其余信息正确。下面是请求/响应的片段。

这是预期的吗?如果是,为什么?

在客户端,我试图过滤掉不是某种特定类型(例如“street_address”)的自动完成预测。这不起作用,因为自动完成响应中的“类型”字段与详细信息响应中返回的“真实”类型值不一致。

谢谢!

“98 Spru”的自动完成请求/响应 https://maps.googleapis.com/maps/api/place/autocomplete/json?input=98%20Spru&sensor=true&key=MYKEY&location=42.350000,-71.160000&radius=100.000000&types=geocode

  {
"description" : "98 Spruce Street, Watertown, MA, United States",
"id" : "013ae3e513081ff1bc9e3dc202df54ba9d147285",
"matched_substrings" : [
{
"length" : 7,
"offset" : 0
}
],
"reference" : "CmRcAAAArJjcgqYuczq9wKmQG0lwv6j_uCBYCrWzS_U76FvnV3fCnWq0_pPf-nu6M9eTYQEpYt4XahA3Vg0GSzMcR23k3Mkxp9sv73ObGmeHDcanEnZ0dWpl69t7eSwmzLbrREQfEhA0CrWTEXtfQhcnfNWnqTukGhQFWBj_lPkoAwG-ZvUIv0GZhgAscQ",
"terms" : [
{
"offset" : 0,
"value" : "98 Spruce Street"
},
{
"offset" : 18,
"value" : "Watertown"
},
{
"offset" : 29,
"value" : "MA"
},
{
"offset" : 33,
"value" : "United States"
}
],
"types" : [ "route", "geocode" ]
},

来自上述预测的详细请求/响应: https://maps.googleapis.com/maps/api/place/details/json?key=MYKEY&sensor=true&reference=CmRcAAAAzcupmv2dCaIWTnySJhA8y4BIc5_VSj1AUXCBFHEVnuo3NGjuqAVrLGSVZ_NODQstUs1ZclGASEzBYTF0B1nFSAcjgrc7Jn9NhJC2GZ2RtQQ3REFV7pvBzTPoGOHew289EhAD7dQFOe2EvBjpQ46IKODbGhTH0scvHs54U3refjf1-Tn6-04XvQ

{
"debug_info" : [],
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "98",
"short_name" : "98",
"types" : [ "street_number" ]
},
{
"long_name" : "Spruce St",
"short_name" : "Spruce St",
"types" : [ "route" ]
},
{
"long_name" : "Watertown",
"short_name" : "Watertown",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Middlesex",
"short_name" : "Middlesex",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Massachusetts",
"short_name" : "MA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "02472",
"short_name" : "02472",
"types" : [ "postal_code" ]
}
],
"adr_address" : "\u003cspan class=\"street-address\"\u003e98 Spruce St\u003c/span\u003e, \u003cspan class=\"locality\"\u003eWatertown\u003c/span\u003e, \u003cspan class=\"region\"\u003eMA\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e02472\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUSA\u003c/span\u003e",
"formatted_address" : "98 Spruce St, Watertown, MA 02472, USA",
"geometry" : {
"location" : {
"lat" : 42.3667790,
"lng" : -71.1698590
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "5e66bbb5a5a7eaedd07fabc199e87570bcc0eae6",
"name" : "98 Spruce St",
"reference" : "CpQBhgAAABX6gm9Qh9r9QxMuEWIrwFGcsz2QnUG0MAoEkD33kwrxfcEakZh-d01oWlAFnIieF8MvVcflI7xJ91Qq2ahnw9oDjcUPUnhlRcOUjLF0lTXOWf3Fp3dbCqLo3MQxCDGT3UJj5fR4ZrPagqBYXtQcPl1TB6sgPHZv8x-2jdJzbh-yZ6yb9VhfG-KDD76-RdotkRIQ7Oz0mKuwaclr0xiIf4oHehoUM2l9nZsi5pU2RPyB7YA2lmJ7vI0",
"types" : [ "street_address" ],
"url" : "https://maps.google.com/maps/place?q=98+Spruce+St&ftid=0x89e3781f4bba528d:0xa7ec6e9a6bde2e4f",
"vicinity" : "Watertown"
},
"status" : "OK"
}

最佳答案

您不能依赖自动完成 API 返回的 googleId。您需要使用引用,对 Place Details API 进行 API 调用,然后使用该 ID。我相信有时 Google 会合并他们的位置数据库,以便引用将“重定向”到新位置。

关于google-places-api - 为什么自动完成响应中的某些信息与后续详细信息响应中返回的信息不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17350414/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com