ban*_*ing 5 javascript google-maps-api-3
所以我能够在我的谷歌地图v3上制作一个圆形物体作为叠加层.我将其editable属性设置为true.我想做的下一件事是,如果用户移动圆圈,则获取中心的坐标.为此,我需要某种方法来响应事件.我以为我在初始化函数中设置了所有这些,如下所示.但是,我没有得到任何警报框.所以我假设这个函数响应事件没有被触发.
任何人都可以帮助我理解和解决这个问题.
function initialize() {
cityCenterLatLng = new google.maps.LatLng(cLat, cLong);
options = {
center : cityCenterLatLng,
zoom : 15,
mapTypeId : google.maps.MapTypeId.ROADMAP,
disableDefaultUI : false,
mapTypeControl : true,
streetViewControl : true,
mapTypeControlOptions : {
style : google.maps.MapTypeControlStyle.DEFAULT,
position : google.maps.ControlPosition.TOP_LEFT
}
};
map = new google.maps.Map(document.getElementById("map_canvas"), options);
$("#map_canvas").css("border", "3px solid black");
infoWindow = new google.maps.InfoWindow({});
var c = {
strokeColor: "#ff0000",
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: "#b0c4de",
fillOpacity: 0.50,
map: map,
center: cityCenterLatLng,
radius: 1000,
editable:true
};
circle = new google.maps.Circle(c);
google.maps.event.addListener(circle, 'distance_changed', function()
{
alert('Circle moved');
//displayInfo(circle);
});
google.maps.event.addListener(circle, 'position_changed', function()
{
alert('dictance changed');
//displayInfo(circle);
});
}
function displayInfo(widget)
{
var info = document.getElementById('info');
info.innerHTML = 'Circle Center:' + circle.get('position') + ',Circle distance: ' +
circle.get('distance');
}
Run Code Online (Sandbox Code Playgroud)
};
function initialize() {
cityCenterLatLng = new google.maps.LatLng(cLat, cLong);
options = {
center : cityCenterLatLng,
zoom : 15,
mapTypeId : google.maps.MapTypeId.ROADMAP,
disableDefaultUI : false,
mapTypeControl : true,
streetViewControl : true,
mapTypeControlOptions : {
style : google.maps.MapTypeControlStyle.DEFAULT,
position : google.maps.ControlPosition.TOP_LEFT
}
};
map = new google.maps.Map(document.getElementById("map_canvas"), options);
$("#map_canvas").css("border", "3px solid black");
infoWindow = new google.maps.InfoWindow({});
var c = {
strokeColor: "#ff0000",
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: "#b0c4de",
fillOpacity: 0.50,
map: map,
center: cityCenterLatLng,
radius: 1000,
editable:true
};
circle = new google.maps.Circle(c);
google.maps.event.addListener(circle, 'distance_changed', function()
{
alert('Circle moved');
//displayInfo(circle);
});
google.maps.event.addListener(circle, 'position_changed', function()
{
alert('dictance changed');
//displayInfo(circle);
});
}
function displayInfo(widget)
{
var info = document.getElementById('info');
info.innerHTML = 'Circle Center:' + circle.get('position') + ',Circle distance: ' +
circle.get('distance');
}
Run Code Online (Sandbox Code Playgroud)
}
function displayInfo(widget)
{
var info = document.getElementById('info');
info.innerHTML ='圆心:'+ circle.get('position')+',圆距:'+ circle.get('distance');
}
Tin*_*ehr 16
更改distance_changed到center_changed了拖运动,并使用radius_changed检测调整.其他事件在文档中.
https://developers.google.com/maps/documentation/javascript/reference#Circle
向下滚动到"活动".
对于新值,在侦听器函数内部,写alert(circle.getCenter());或circle.getRadius()
| 归档时间: |
|
| 查看次数: |
12676 次 |
| 最近记录: |