【发布时间】:2020-08-14 11:25:57
【问题描述】:
在我的前端(反应)要求之一中,一旦从自动完成建议中选择了一个地方,我需要获取全球国家名称、州名、城市名称、placeId、纬度和经度。我能够从响应的几何键中获取城市名称(来自名称键)、placeId、纬度和经度。我正在使用这个 google 脚本,使用 place api 服务 => ---------------------------------- this.autocomplete = 新 google.maps.places.Autocomplete(this.autocompleteInput.current, {“类型”:['(城市)']}); this.autocomplete.addListener('place_changed', this.handlePlaceChanged); ---------------------------------- 在 handlePlaceChanged 函数中,我得到以下响应 =>>
{"address_components":[{"long_name":"Bengaluru","short_name":"Bengaluru","types":
["locality","political"]},{"long_name":"Bangalore Urban","short_name":"Bangalore 城市","类型":["administrative_area_level_2","political"]}, {"long_name":"卡纳塔克邦","short_name":"KA","types": ["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types": ["country","political"]}],"adr_address":"Bengaluru, Karnataka, India","formatted_address":"Bengaluru, Karnataka, India","geometry": {"location":{"lat":12.9715987,"lng":77.5945627},"viewport":{"south":12.7342888,"west":77.3791981,"north":13.173706,"east":77.8826809}}, "icon":"https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png","id":"0862832923832bfb1e46cbe843cdaa03a9ee8aa1","name":"Bengaluru","photos":[{"height":405,"html_attributions":["https://maps. google.com/maps/contrib/113170619945048632846\">abdusamad k"],"width":720},{"height":385,"html_attributions":["https://maps.google.com/maps/contrib /105596602452460947497\">Rince TR"],"width":796},{"height":2340,"html_attributions":["https://maps.google.com/maps/contrib/107994729306954910118\">Riju Pal "],"width":4160},{"height":315,"html_attributions":["https://maps.google.com/maps/contrib/101926288772104749853\">Dipendra Bist"],"width": 534},{"高度":2592,"html_attributions":["https://maps.google.com/maps/contrib/100418682723295961842\">Achyuth rupavatharam"],"宽度":1944},{"高度" :424,"html_attributions":["https://maps.google.com/maps/contrib/118332000005283281641\">Jerin Asher Sojan"],"width":640},{"heigh t":2448,"html_attributions":["https://maps.google.com/maps/contrib/102738049583390423145\">DEBAJYOTI GHATAK"],"width":3264},{"height":789,"html_attributions ":["https://maps.google.com/maps/contrib/109699434808207248873\">nitin kumar"],"width":1080},{"height":3024,"html_attributions":["https:// /maps.google.com/maps/contrib/109460450047584922534\">Blue Dares"],"width":4032},{"height":738,"html_attributions":["https://maps.google.com/ maps/contrib/116995855942077255039\">Chelsy Halder"],"width":1599}],"place_id":"ChIJbU60yXAWrjsR4E9-UejD3_g","reference":"ChIJbU60yXAWrjsR4E9-UejD3_g","scope":"GOOGLE","类型":["locality","political"],"url":"https://maps.google.com/?q=Bengaluru,+Karnataka,+India&ftid=0x3bae1670c9b44e6d:0xf8dfc3e8517e4fe0","utc_offset":330,"vicinity":"Bengaluru","html_attributions":[],"utc_offset_minutes":330}
=============================================================
I need guidance on how should I get Country name, State name, City name globally
【问题讨论】:
标签: reactjs googleplacesautocomplete