filter only sublocalities in google maps api

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-17 02:15:14

问题


I want to get nearby sublocalities in google maps api

var input = document.getElementById('searchTextField');         
    var autocomplete = new google.maps.places.Autocomplete(input, {
        types: ["geocode"]
    });          

This adds autocomplete for all places being typed in the text box. I want to filter out only the sublocalities and get the nearby sub localities in the autocomplete

Check the working version here


回答1:


Types: ["(cities)"] will give you just localities.

From the documentation :

"types | Type: Array | The types of predictions to be returned. Four types are supported: 'establishment' for businesses, 'geocode' for addresses, '(regions)' for administrative regions and '(cities)' for localities. If nothing is specified, all types are returned."

var input = document.getElementById('searchTextField');         
var autocomplete = new google.maps.places.Autocomplete(input, {
    types: ["(cities)"]
}); 



回答2:


I had a similar usecase too. I did not have a way to do it using google maps api. But, you can try getting geometry (lat, lng) from Autocomplete getPlaces() and use geonames.org API to get nearby sublocalities giving lat, lng and radius

http://api.geonames.org/findNearbyPlaceNameJSON?lat=13.041703&lng=80.251943&radius=5&username=demo



来源:https://stackoverflow.com/questions/33435076/filter-only-sublocalities-in-google-maps-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!