Google maps api 3 计算圆中的标记 基于这个例子,但是圆中的记号不准确,当标记在圆外且接近圆时,考虑在不需要的圆内。

Google maps api 3 计算圆中的标记 基于这个例子,但是圆中的记号不准确,当标记在圆外且接近圆时,考虑在不需要的圆内。,google-maps-api-3,Google Maps Api 3,还有其他想法吗 代码片段(来自链接的小提琴): window.onload=函数init(){ 变量 contentCenter='中心标记(可拖动)', contentA='标记A(可拖动)', contentB='标记B(可拖动)'; 变量 latLngCenter=new google.maps.LatLng(37.081476,-94.510574), latLngCMarker=new google.maps.LatLng(37.0814,-94.5105), latLngA=new

还有其他想法吗

代码片段(来自链接的小提琴):

window.onload=函数init(){
变量
contentCenter='中心标记(可拖动)',
contentA='标记A(可拖动)',
contentB='标记B(可拖动)';
变量
latLngCenter=new google.maps.LatLng(37.081476,-94.510574),
latLngCMarker=new google.maps.LatLng(37.0814,-94.5105),
latLngA=new google.maps.LatLng(37.2,-94.1),
latLngB=new google.maps.LatLng(38,-93),
map=new google.maps.map(document.getElementById('map'){
缩放:7,
中心:latLngCenter,
mapTypeId:google.maps.mapTypeId.ROADMAP,
mapTypeControl:false
}),
markerCenter=new google.maps.Marker({
位置:latLngCMarker,
标题:“地点”,
地图:地图,
德拉格布尔:是的
}),
信息中心=新建google.maps.InfoWindow({
内容:资源中心
}),
markerA=new google.maps.Marker({
职位:latLngA,
标题:“地点”,
地图:地图,
德拉格布尔:是的
}),
infoA=新建google.maps.InfoWindow({
内容:内容A
}),
markerB=新的google.maps.Marker({
位置:latLngB,
标题:“地点”,
地图:地图,
德拉格布尔:是的
}),
infoB=新建google.maps.InfoWindow({
内容:内容B
})
//示例性设置:
//假设您的映射已签名到var“map”
//还假定您的标记名为“marker”
,
圆圈=新的google.maps.circle({
地图:地图,
可点击:false,
//米
半径:100000,
fillColor:“#fff”,
不透明度:.6,
strokeColor:“#313131”,
冲程不透明度:.4,
冲程重量:.8
});
//将圆圈附加到标记上
圆圈.bindTo('center',markerCenter',position');
变量
//得到圆的边界
bounds=circle.getBounds()
//音符跨度
,
noteA=jQuery('.bool#a'),
noteB=jQuery('.bool#b');
noteA.text(bounds.contains(latLngA));
noteB.text(bounds.contains(latLngB));
//获取一些latLng对象并询问它是否包含在圆中:
google.maps.event.addListener(markerCenter'dragend',function(){
latLngCenter=new google.maps.LatLng(markerCenter.position.lat(),markerCenter.position.lng());
bounds=circle.getBounds();
noteA.text(bounds.contains(latLngA));
noteB.text(bounds.contains(latLngB));
});
google.maps.event.addListener(markerA,'dragend',function(){
latLngA=new google.maps.LatLng(markerA.position.lat(),markerA.position.lng());
noteA.text(bounds.contains(latLngA));
});
google.maps.event.addListener(markerB,'dragend',function(){
latLngB=new google.maps.LatLng(markerB.position.lat(),markerB.position.lng());
noteB.text(bounds.contains(latLngB));
});
google.maps.event.addListener(markerCenter,'click',function(){
打开(地图、markerCenter);
});
google.maps.event.addListener(markerA,'click',function(){
infoA.open(地图、markerA);
});
google.maps.event.addListener(markerB,'click',function(){
信息公开(地图,markerB);
});
google.maps.event.addListener(markerCenter,'drag',function(){
infoCenter.close();
html(“draggin…”);
html(“draggin…”);
});
google.maps.event.addListener(markerA,'drag',function(){
infoA.close();
html(“draggin…”);
});
google.maps.event.addListener(markerB,'drag',function(){
infoB.close();
html(“draggin…”);
});
};
正文{
保证金:0;
填充:0
}
html,
身体,
#地图{
身高:100%;
字体系列:Arial,无衬线;
字体大小:.9em;
颜色:#fff;
}
#注{
文本对齐:居中;
填充:.3em;
10px;
背景:009ee0;
}
布尔先生{
字体:斜体;
颜色:#313131;
}
.info{
显示:内联块;
宽度:40%;
文本对齐:居中;
}
.infowin{
颜色:#313131;
}
#头衔,
布尔先生{
字体大小:粗体;
}

&拉阔;圈内?«;

标记A:&larr&直径→标记B
test
google.maps.LatLngBounds是一个矩形。您需要一个多边形“包含”函数。对于圆,这可以简化为测试点是否小于距中心的半径

代码片段:

window.onload=函数init(){
变量
contentCenter='中心标记(可拖动)',
contentA='标记A(可拖动)',
contentB='标记B(可拖动)';
变量
latLngCenter=new google.maps.LatLng(37.081476,-94.510574),
latLngCMarker=new google.maps.LatLng(37.0814,-94.5105),
latLngA=new google.maps.LatLng(37.2,-94.1),
latLngB=new google.maps.LatLng(38,-93),
map=new google.maps.map(document.getElementById('map'){
缩放:7,
中心:latLngCenter,
mapTypeId:google.maps.mapTypeId.ROADMAP,
mapTypeControl:false
}),
markerCenter=new google.maps.Marker({
位置:latLngCMarker,
标题:“圆心”,
地图:地图,
德拉格布尔:是的
}),
信息中心=新建google.maps.InfoWindow({
内容:资源中心
}),
markerA=new google.maps.Marker({
职位:latLngA,
标题:"A",,
地图:地图,
标签:“A”,
德拉格布尔:是的
}),
infoA=新建google.maps.InfoWindow({
内容:内容A
}),
markerB=新的google.maps.Marker({
位置:latLngB,
标题:“B”,
地图:地图,
标签:“B”,
德拉格布尔:是的
}),
infoB=新建google.maps.InfoWindow({
内容:内容B
})
//示例性设置:
//假设您的映射已签名到var“map”
//还假定您的标记名为“marker”
,
circle=new google.ma