为什么自动填充响应中的某些信息与后续详细信息响应中返回的信息不同?

时间:2013-06-27 18:15:46

标签: google-places-api

当我执行“98 Spru”的Google地方信息自动填充请求时,我会获得一个地方预测,其中包含一个ID(013ae3e513081ff1bc9e3dc202df54ba9d147285)和一组类型(“路由”和“地理编码”),但是当我获取详细信息时它有不同的ID(5e66bbb5a5a7eaedd07fabc199e87570bcc0eae6)和一组不同的类型(“street_address”)?其余信息是正确的。下面的请求/回复片段。

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

在客户端,我正在尝试过滤掉某些特定类型的自动填充预测(例如“street_address”)。这不起作用,因为自动填充响应中的“类型”字段与“详细信息”响应中返回的“true”类型值不一致。

谢谢!

“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"
}

1 个答案:

答案 0 :(得分:0)

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