get city from geocoder results?

后端 未结 13 1907
我寻月下人不归
我寻月下人不归 2020-12-02 14:07

Having problems getting the different arrays content from geocoder results.

item.formatted_address works but not item.address_components.locality?

ge         


        
13条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 15:00

    Returns locality if exist. If not - returns administrative_area_1

    city = results[0].address_components.filter(function(addr){
       return (addr.types[0]=='locality')?1:(addr.types[0]=='administrative_area_level_1')?1:0;
    });
    

提交回复
热议问题