Javascript 谷歌地图自动完成没有大气数据

Javascript 谷歌地图自动完成没有大气数据,javascript,json,google-maps,google-maps-api-3,google-places-api,Javascript,Json,Google Maps,Google Maps Api 3,Google Places Api,我目前正在使用Google Maps Places Autocomplete Javascript API,让用户通过搜索地址或机构名称来选择位置。 示例代码: autocomplete = new google.maps.places.Autocomplete(input); google.maps.event.addListener(autocomplete, 'place_changed', function () { console.log(autocomplete.getPla

我目前正在使用Google Maps Places Autocomplete Javascript API,让用户通过搜索地址或机构名称来选择位置。 示例代码:

autocomplete = new google.maps.places.Autocomplete(input);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
    console.log(autocomplete.getPlace());
});
这将获得以下数据

{  
   "address_components":[  
      {  
         "long_name":"1600",
         "short_name":"1600",
         "types":[  
            "street_number"
         ]
      },
      {  
         "long_name":"Amphitheatre Parkway",
         "short_name":"Amphitheatre Pkwy",
         "types":[  
            "route"
         ]
      },
      {  
         "long_name":"Mountain View",
         "short_name":"Mountain View",
         "types":[  
            "locality",
            "political"
         ]
      },
      {  
         "long_name":"Santa Clara County",
         "short_name":"Santa Clara County",
         "types":[  
            "administrative_area_level_2",
            "political"
         ]
      },
      {  
         "long_name":"California",
         "short_name":"CA",
         "types":[  
            "administrative_area_level_1",
            "political"
         ]
      },
      {  
         "long_name":"United States",
         "short_name":"US",
         "types":[  
            "country",
            "political"
         ]
      },
      {  
         "long_name":"94043",
         "short_name":"94043",
         "types":[  
            "postal_code"
         ]
      }
   ],
   "adr_address":"<span class=\"street-address\">1600 Amphitheatre Pkwy</span>, <span class=\"locality\">Mountain View</span>, <span class=\"region\">CA</span> <span class=\"postal-code\">94043</span>, <span class=\"country-name\">USA</span>",
   "formatted_address":"1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
   "formatted_phone_number":"(650) 253-0000",
   "geometry":{  
      "location":{  
         "lat":37.4219999,
         "lng":-122.08405749999997
      },
      "viewport":{  
         "south":37.4206993697085,
         "west":-122.0847981802915,
         "north":37.4233973302915,
         "east":-122.08210021970848
      }
   },
   "icon":"https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
   "id":"3a936e96ddcb18b4fa8a2974ebc8876c3108fef2",
   "international_phone_number":"+1 650-253-0000",
   "name":"Googleplex",
   "photos":[  
      {  
         "height":2992,
         "html_attributions":[  
            "<a href=\"https://maps.google.com/maps/contrib/103819965142360016765/photos\">Donald Polak</a>"
         ],
         "width":4000
      },
      {  
         "height":1080,
         "html_attributions":[  
            "<a href=\"https://maps.google.com/maps/contrib/113986172004889046503/photos\">Gil Carlos</a>"
         ],
         "width":1620
      },
      {  
         "height":810,
         "html_attributions":[  
            "<a href=\"https://maps.google.com/maps/contrib/112693353017475869362/photos\">spoorthi Shres</a>"
         ],
         "width":1080
      },
      {  
         "height":2448,
         "html_attributions":[  
            "<a href=\"https://maps.google.com/maps/contrib/112322727489597014623/photos\">Inmook Lee</a>"
         ],
         "width":3264
      },
      {  
         "height":480,
         "html_attributions":[  
            "<a href=\"https://maps.google.com/maps/contrib/100130762972482716067/photos\">JL N</a>"
         ],
         "width":640
      },
      {  
         "height":2988,
         "html_attributions":[  
            "<a href=\"https://maps.google.com/maps/contrib/112927044171481932986/photos\">Chamnan Muon</a>"
         ],
         "width":5312
      },
      {  
         "height":2448,
         "html_attributions":[  
            "<a href=\"https://maps.google.com/maps/contrib/112947157334846208308/photos\">Aslam Mohammed</a>"
         ],
         "width":3264
      },
      {  
         "height":3024,
         "html_attributions":[  
            "<a href=\"https://maps.google.com/maps/contrib/111560452835833490678/photos\">Emprendedor ypunto</a>"
         ],
         "width":4032
      },
      {  
         "height":2268,
         "html_attributions":[  
            "<a href=\"https://maps.google.com/maps/contrib/112821956543329496349/photos\">Remco Buddelmeijer</a>"
         ],
         "width":4032
      },
      {  
         "height":3024,
         "html_attributions":[  
            "<a href=\"https://maps.google.com/maps/contrib/112778094015197614835/photos\">Thais Ferreira Curi</a>"
         ],
         "width":4032
      }
   ],
   "place_id":"ChIJj61dQgK6j4AR4GeTYWZsKWw",
   "plus_code":{  
      "compound_code":"CWC8+Q9 Mountain View, California, United States",
      "global_code":"849VCWC8+Q9"
   },
   "rating":4.4,
   "reference":"CmRRAAAACSrJEHCvJp1k1sNsnP1YvwaVcHxCPCdgt9vF-dLxsyUO-VoVoJ44QUHBeay_xRA29z7r9M_Pl-GCRFke9AbTjR7uOQg6ujPCc2gI3yaVlTVIBOAfxlamFaYbwzInWZDYEhA6V8crd3XJ8w-LHYNjzm2RGhSjYXAaGOf9ewF1emkXjxFJu-tO7g",
   "reviews":[  
      {  
         "author_name":"Grand Palais Beachside",
         "author_url":"https://www.google.com/maps/contrib/117946213840380407904/reviews",
         "language":"en",
         "profile_photo_url":"https://lh3.googleusercontent.com/-f_xOeqEuQlY/AAAAAAAAAAI/AAAAAAAAAAA/AAnnY7oSEuVFn-pDYQWJEJTa0Ol6FC6oLw/s128-c0x00000000-cc-rp-mo/photo.jpg",
         "rating":5,
         "relative_time_description":"in the last week",
         "text":"How would you rate your experience with The Marble Man?  \nThe experience was excellent, totally professional, provided great advice on work timings and even when running a little late had the professionalism to advise us and that was very much appreciated.\nDo you have any suggestions on how we can improve in any areas?\nNot be so busy that we had to wait a month (approx.) but no in all honesty great service very happy but in running a resort sometimes these in the future need to be acted on asap as they are unable to be let depending on the repair required.\nHow was the completed job?\nExcellent\nHow did you find our job and inspection technicians and office team?\nExcellent\nWe would 100% recommend the team at Marble Man to all.",
         "time":1534208819
      },
      {  
         "author_name":"BRYAN HALLIGAN",
         "author_url":"https://www.google.com/maps/contrib/105850575620900701772/reviews",
         "language":"en",
         "profile_photo_url":"https://lh5.googleusercontent.com/-qlpyjtK9t8E/AAAAAAAAAAI/AAAAAAAAAAc/euGPm7V8gRA/s128-c0x00000000-cc-rp-mo/photo.jpg",
         "rating":1,
         "relative_time_description":"in the last week",
         "text":"You can use AutocompleteOptions object in order to define fields that you want to see in details responses. AutocompleteOptions has a 
fields
property

fields - Fields to be included for the Place in the details response when the details are successfully retrieved. For a list of fields see PlaceResult. Nested fields can be specified with dot-paths (for example, "geometry.location").

So, you can change autocomplete initialization to the following form

autocomplete = new google.maps.places.Autocomplete(input, {
    fields: ["name", "geometry.location", "place_id", "formatted_address"]
});
{
“地址/组件”:[
{  
“long_name”:“1600”,
“短名称”:“1600”,
“类型”:[
“街道号码”
]
},
{  
“龙_名称”:“竞技场公园道”,
“短名称”:“圆形剧场Pkwy”,
“类型”:[
“路线”
]
},
{  
“龙_名称”:“山景”,
“短名称”:“山景”,
“类型”:[
“地点”,
“政治”
]
},
{  
“long_名称”:“圣克拉拉县”,
“短名称”:“圣克拉拉县”,
“类型”:[
“行政区二级”,
“政治”
]
},
{  
“long_name”:“California”,
“短名称”:“CA”,
“类型”:[
“行政区一级”,
“政治”
]
},
{  
“long_name”:“美国”,
“简称”:“美国”,
“类型”:[
“国家”,
“政治”
]
},
{  
“long_name”:“94043”,
“短名称”:“94043”,
“类型”:[
“邮政编码”
]
}
],
“adr_地址”:“美国加利福尼亚州山景城1600圆形剧场Pkwy,邮编94043”,
“格式化地址”:“美国加利福尼亚州山景城1600圆形剧场Pkwy,邮编94043”,
“格式化电话号码”:(650)253-0000,
“几何学”:{
“地点”:{
“lat”:37.4219999,
“液化天然气”:-122.084057499997
},
“视口”:{
“南”:37.4206993697085,
“西部”:-122.0847981802915,
“北”:37.4233973302915,
“东”:-122.08210021970848
}
},
“图标”:”https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
“id”:“3a936e96ddcb18b4fa8a2974ebc8876c3108fef2”,
“国际电话号码”:“+1650-253-0000”,
“名称”:“Googleplex”,
“照片”:[
{  
“高度”:2992,
“html_属性”:[
""
],
“宽度”:4000
},
{  
“高度”:1080,
“html_属性”:[
""
],
“宽度”:1620
},
{  
“高度”:810,
“html_属性”:[
""
],
“宽度”:1080
},
{  
“高度”:2448,
“html_属性”:[
""
],
“宽度”:3264
},
{  
“高度”:480,
“html_属性”:[
""
],
“宽度”:640
},
{  
“高度”:2988,
“html_属性”:[
""
],
“宽度”:5312
},
{  
“高度”:2448,
“html_属性”:[
""
],
“宽度”:3264
},
{  
“高度”:3024,
“html_属性”:[
""
],
“宽度”:4032
},
{  
“高度”:2268,
“html_属性”:[
""
],
“宽度”:4032
},
{  
“高度”:3024,
“html_属性”:[
""
],
“宽度”:4032
}
],
“地点id”:“ChIJj61dQgK6j4AR4GeTYWZsKWw”,
“加号”:{
“复合_代码”:“美国加利福尼亚州山景城CWC8+Q9”,
“全局_代码”:“849VCWC8+Q9”
},
“评级”:4.4,
“参考文件”:“CMRRAAACSRJEHCVJP1K1SNP1YVWAVCHxCPCDGT9VF-dLxsyUO-VoVoJ44QUHBeay_xRA29z7r9M_Pl-GCRFKE9ABTJR7UOQG6UJPCC2Gi3YAVLTVIBOAFLAMFAYBWZYZDYHA6V8CRD3XJ8W-LHYNJZM2RGHYXJAGYXAGOF9EWF1EMKXJJJJJJJU-tO7g”,
“审查”:[
{  
“作者姓名”:“海滨大皇宫”,
“作者url”:https://www.google.com/maps/contrib/117946213840380407904/reviews",
“语言”:“en”,
“配置文件\照片\ url”:https://lh3.googleusercontent.com/-f_xOeqEuQlY/AAAAAAAAAAI/AAAAAAAAAAA/AAnnY7oSEuVFn-pDYQWJEJTa0Ol6FC6oLw/s128-c0x00000000-cc-rp-mo/photo.jpg",
“评级”:5,
“相对时间描述”:“上周”,
“文本”:"您如何评价您与“大理石人”的合作经验?\n该经验非常出色,非常专业,在工作时间安排方面提供了很好的建议,即使有点晚,您也能以专业的态度向我们提供建议,我们对此深表感谢。\n您对我们在任何方面如何改进有什么建议吗?\n我们不会太忙,因此d等待一个月(约)但不,说实话,服务很好,非常满意,但在经营度假村时,有时需要尽快采取行动,因为根据所需的维修,这些设备无法出租。\n工作是如何完成的?\nXcellent\n您是如何找到我们的工作和检查技术员及办公室团队的?\nXcellent\n我们将100%推荐Ma的团队“人人平等。”,
“时间”:1534208819
},
{  
“作者姓名”:“布莱恩·哈利根”,
“作者url”:https://www.google.com/maps/contrib/105850575620900701772/reviews",
“语言”:“en”,
“配置文件\照片\ url”:https://lh5.googleusercontent.com/-qlpyjtK9t8E/AAAAAAAAAAI/AAAAAAAAAAc/euGPm7V8gRA/s128-c0x00000000-cc-rp-mo/photo.jpg",
“评级”:1,
“相对时间描述”:“上周”,
“文本”:“您可以使用object来定义要在详细信息响应中查看的字段。AutocompleteOptions具有
字段
属性

字段-成功检索详细信息时,将在详细信息响应中包含该位置的字段。有关字段列表,请参阅PlaceResult。可以使用点路径指定嵌套字段(例如,“geometry.location”)

因此,您可以将自动完成初始化更改为以下形式

var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.setFields(['address_components', 'formatted_address', 'geometry', 'icon', 'name']);
我希望这有帮助
autocomplete.setFields(['address_components', 'formatted_address', 'geometry', 'icon', 'name']);