我在卷曲中使用的自动填充网址是
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=JFK&key=<<<KEY>>>&types=geocode&fields=airport,photos,icon,geometry
并返回此
{"predictions":[{"description":"JFK - Terminal 7, Jamaica, NY, USA","id":"f67e5c44e0c45e7f4a49ed96bd737bc70d3a1e42","matched_substrings":[{"length":3,"offset":0}],"place_id":"ChIJOV8Ah_dmwokRXifsiI5gs9E","reference":"ChIJOV8Ah_dmwokRXifsiI5gs9E","structured_formatting":{"main_text":"JFK - Terminal 7","main_text_matched_substrings":[{"length":3,"offset":0}],"secondary_text":"Jamaica, NY, USA"},"terms":[{"offset":0,"value":"JFK - Terminal 7"},{"offset":18,"value":"Jamaica"},{"offset":27,"value":"NY"},{"offset":31,"value":"USA"}],"types":["premise","geocode"]},{"description":"Terminal 5, Jamaica, NY, USA","id":"27fb6511d4bfacef4563c3cc25c3b1aed9098c56","matched_substrings":[{"length":10,"offset":0}],"place_id":"ChIJG45Wb19mwokRNXsvcPYOEzo","reference":"ChIJG45Wb19mwokRNXsvcPYOEzo","structured_formatting":{"main_text":"Terminal 5","main_text_matched_substrings":[{"length":10,"offset":0}],"secondary_text":"Jamaica, NY, USA"},"terms":[{"offset":0,"value":"Terminal 5"},{"offset":12,"value":"Jamaica"},{"offset":21,"value":"NY"},{"offset":25,"value":"USA"}],"types":["premise","geocode"]}],"status":"OK"}
我正在尝试获取机场1号的名称,然后再进行其他任何匹配。但是我似乎有时候去机场,有时我只是航站楼。
我正在尝试使其像mozio一样工作,如果您输入肯尼迪国际机场,肯尼迪国际机场将排在第一位,然后是机场。我的网址中缺少什么类型/字段?谢谢
答案 0 :(得分:0)
尝试使用场所自动完成Web服务支持的establishment
类型参数。
当我执行以下请求时
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=JFK&types=establishment&key=MY_API_KEY
第一个预测是
美国纽约州皇后区的肯尼迪国际机场(JFK)(地点ID ChIJR0lA1VBmwokR8BGfSBOyT-w)
您可以在Geocoder工具中看到该地点:
我希望这会有所帮助!