Google maps 带边界的谷歌地图地理编码
当我得到一个结果时,使用下面的代码,我似乎无法得到结果的完整地址组件,我们正在使用这些组件与其他服务一起确定各种事情 我一出界,一切都很好。但我还是需要限制在一定范围内 为什么会这样?我怎样才能解决这个问题呢 代码: 要将边界添加到,它将进入请求对象内部:Google maps 带边界的谷歌地图地理编码,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,当我得到一个结果时,使用下面的代码,我似乎无法得到结果的完整地址组件,我们正在使用这些组件与其他服务一起确定各种事情 我一出界,一切都很好。但我还是需要限制在一定范围内 为什么会这样?我怎样才能解决这个问题呢 代码: 要将边界添加到,它将进入请求对象内部: var data = { bounds: { west: -25.806884999999966, east: 16.380615000000034, south: 48.98742739340465, n
var data = {
bounds: {
west: -25.806884999999966,
east: 16.380615000000034,
south: 48.98742739340465,
north: 60.16884190739975
}
};
var bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(data.bounds.south, data.bounds.west),
new google.maps.LatLng(data.bounds.north, data.bounds.east));
geocoder.geocode({
address: "London",
bounds: bounds
}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
注意但是:
可选参数:
边界-偏移地理编码结果的后边界更显著边界参数将仅影响而不是完全限制地理编码器的结果。(有关详细信息,请参见下面的视口偏移。)
代码片段:
函数初始化(){
var map=new google.maps.map(
document.getElementById(“地图画布”){
中心:新google.maps.LatLng(37.4419,-122.1419),
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
风险值数据={
界限:{
西:-25.806884999966,
东:16.3806150000034,
南:48.98742739340465,
北:60.16884190739975
}
};
var bounds=new google.maps.LatLngBounds(new google.maps.LatLng(data.bounds.south,data.bounds.west),new google.maps.LatLng(data.bounds.north,data.bounds.east));
var rectangle=new google.maps.rectangle({
地图:地图,
界限:界限
});
映射边界(bounds);
var geocoder=new google.maps.geocoder();
地理编码({
地址:“伦敦”,
界限:界限
},功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK){
var marker=new google.maps.marker({
位置:结果[0]。geometry.location,
地图:地图
});
}否则{
警报('地理编码因以下原因未成功:'+状态);
}
});
}
google.maps.event.addDomListener(窗口“加载”,初始化)代码>
html,
身体,
#地图画布{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}
请提供一份说明问题的报告。失败的实际调用是什么(或者至少是失败调用的示例)。\uuu.extend
来自哪里?您希望它做什么?(在我看来,您在提供的代码片段中有语法错误)边界正在工作,这很好,问题是,相同的搜索在地址\u组件
数组中返回的更少当边界就位时,我需要一整套地址\u组件
请在您的问题中澄清您的问题。
var data = {
bounds: {
west: -25.806884999999966,
east: 16.380615000000034,
south: 48.98742739340465,
north: 60.16884190739975
}
};
var bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(data.bounds.south, data.bounds.west),
new google.maps.LatLng(data.bounds.north, data.bounds.east));
geocoder.geocode({
address: "London",
bounds: bounds
}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});