2013-06-27 58 views
3

當我爲「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" 
} 
+0

有沒有更新?我也注意到這個問題,因爲自動填充和地點詳細信息的ID不同。 – sthomps

回答

0

你不能依靠googleId多數民衆贊成由歸國自動完成API。您需要使用該參考,對Place Details API進行API調用,然後使用該ID。我相信Google有時會整合他們的地點數據庫,以便引用將「重定向」到一個新的地方。