[英]Getting Updated Radius/Area in Google Maps API v3
我在我們的網站上有一張地圖,人們可以借鑒該地圖來提交一個區域以供市場考慮。 我們終於將其更新為新的v3 API,但是我似乎缺少一個功能。 編輯圓形或多邊形時,地圖下方的半徑/區域顯示不會隨着編輯內容而調整。 我認為問題出在這段代碼中,但我不確定。 有任何想法嗎? ( 這里的工作示例 )
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);
}
removeOverlay和GLatLng是v2函數:
map.removeOverlay(circle);
在v3中使用:
circle.setMap(null);
您發布的代碼看起來好像沒有在實時頁面中實際使用。 您可能想向圓添加一個radius_changed偵聽器,並在其中更新計算。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.