Javascript Geocoder API仅返回街道地址
我从Google的geocoder API开始,我只想返回一个位置类型的街道地址 唯一的问题是,我不知道该由谁提出具体要求。这是我现在的代码:Javascript Geocoder API仅返回街道地址,javascript,google-geocoder,Javascript,Google Geocoder,我从Google的geocoder API开始,我只想返回一个位置类型的街道地址 唯一的问题是,我不知道该由谁提出具体要求。这是我现在的代码: var geocoder = new google.maps.Geocoder(); geocoder.geocode({'latLng':myLatLng}, function(results, status){ if(status == google.maps.GeocoderStatus.OK){ if(results.le
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\u address类型?使用
componentRestrictions
参数并指定street\u address
组件,如下所示:
geocoder.geocode({
componentRestrictions:{
street_address:'Avenue of The Stars',
}
}, ... )
这样,您将省略地址
参数,因为您正在查询特定的街道地址
组件
您还可以组合一个或任意数量的组件和地址
参数:
geocoder.geocode({
address:'stars',
componentRestrictions:{
country:'United States',
city:'Los Angeles',
}
}, ... )
这样,Geocode将搜索任何包含字符串“stars”的组件类型
您可以在此处找到其他可查询组件的列表: