我从Google的地理编码器API开始,我想只返回street_address的location_type。
唯一的问题是我不知道具体要求谁。这是我现在的代码:
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng':myLatLng}, function(results, status){
if(status == google.maps.GeocoderStatus.OK){
if(results.length > 0){
console.log(results);
}
else{
alert('nope');
}
}
else{
alert('nope');
}
});
如何指定我只需要类型street_address?
答案 0 :(得分:0)
使用componentRestrictions
参数并指定您的street_address
组件,如下所示:
geocoder.geocode({
componentRestrictions:{
street_address:'Avenue of The Stars',
}
}, ... )
这样就省略了address
param,因为您正在查询特定的street_address
组件。
您还可以组合一个或任意数量的组件以及address
参数:
geocoder.geocode({
address:'stars',
componentRestrictions:{
country:'United States',
city:'Los Angeles',
}
}, ... )
这样Geocode将搜索包含字符串'stars'的任何组件类型。
您可以在此处找到其他可查询组件的列表:https://developers.google.com/maps/documentation/geocoding/#Types