我在我们网站上有一张地图,人们可以借此提交一个区域供市场考虑。我们最终将它更新到了新的v3 API,但我似乎缺少一个函数。编辑圆形或多边形时,地图下方的半径/区域显示不会随编辑进行调整。我认为问题在于这段代码,但我不确定。有任何想法吗? (Working example here)
var map;
var poly;
function initialize() {
map = new google.maps.Map(
document.getElementById('map'), {
center: new google.maps.LatLng(40.3749, -75.2988),
zoom: 15,
disableDoubleClickZoom: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
//map.clearOverlays();
//map.enableGoogleBar();
featureTable_ = document.getElementById("featuretbody");
select("hand_b");
}
google.maps.event.addDomListener(window, 'load', initialize);
function calcCircleArea(radius)
{
var area = 0;
area = (Math.PI * (radius * radius));
return area;
}
function updateCircle(circle,point)
{
circle_bounds = circle.getBounds();
c_vertex = circle_bounds.getCenter();
var distance = c_vertex.distanceFrom(point);
circle.setMap(null);
circle = drawCircle(c_vertex, distance,20, '#ff0000', 1, 0.5, '#ff0000', 0.5);
}
function drawCircle(center, radius, nodes, line_color, liWidth, line_opacity, fill_color, fill_opacity)
{
// calc km/degree
var latC = center.distanceFrom(new google.maps.LatLng(center.lat()+0.1, center.lng()))/100;
var lngC = center.distanceFrom(new google.maps.LatLng(center.lat(), center.lng()+0.1))/100;
//calc circle points
var points = [];
var step = parseInt(360/nodes)||10;
for(var i=0; i<=360; i+=step)
{
var pint = new google.maps.LatLng(
center.lat() + (radius/latC * Math.cos(i * Math.PI/180)),
center.lng() + (radius/lngC * Math.sin(i * Math.PI/180))
);
points.push(pint);
}
答案 0 :(得分:1)
removeOverlay是一个v2函数,就像GLatLng:
一样 map.removeOverlay(circle);
在v3中使用:
circle.setMap(null);
看起来您发布的代码实际上并不在实际页面中使用。您可能希望在圆圈中添加radius_changed侦听器并更新其中的计算。