我正在使用谷歌v3 js,我试图在人们拖动圆圈或展开圆圈时获得圆圈的中心。目前我不知道任何能够触发的事件
<script type="text/javascript">
var latt = 1.3738459931841047;
var longg = 103.79745483398437;
var radius = 1000;
function alertame(lat, long) {
document.getElementById("<%= lblLatitute.ClientID %>").textContent = lat;
document.getElementById("<%= lblLongitude.ClientID %>").textContent = long;
latt = lat;
longg = long;
}
function show_alert() {
alert(latt + "hello"+radius);
}
function initialize() {
var myOptions = {
center: new google.maps.LatLng(1.3738459931841047, 103.79745483398437),
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var circleOptions = {
center: new google.maps.LatLng(latt, longg),
radius: radius,
map: map,
editable: true
};
var circle = new google.maps.Circle(circleOptions);
google.maps.event.addListener(circle, 'radius_changed', function () {
radius = circle.getRadius();
alert("test");
});
google.maps.event.addListener(circle, 'drag', function () {
alert("test");
});
circle.setMap(map);
}
</script>
<style type="text/css">
.style1
{
width: 124px;
}
</style>
答案 0 :(得分:2)
使用以下
解决<script type="text/javascript">
var latt = 1.3738459931841047;
var longg = 103.79745483398437;
var radius = 1000;
var marker;
function show_alert() {
alert(latt + "hello"+radius);
}
function initialize() {
document.getElementById("<%= lblLatitute.ClientID %>").textContent = latt;
document.getElementById("<%= lblLongitude.ClientID %>").textContent = longg;
document.getElementById("<%= lblRadius.ClientID %>").textContent = radius;
var myOptions = {
center: new google.maps.LatLng(1.3738459931841047, 103.79745483398437),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var circleOptions = {
center: new google.maps.LatLng(latt, longg),
radius: radius,
map: map,
editable: true
};
var circle = new google.maps.Circle(circleOptions);
google.maps.event.addListener(circle, 'radius_changed', function () {
radius = circle.getRadius();
latt = circle.getCenter().lat();
longg = circle.getCenter().lng();
document.getElementById("<%= lblRadius.ClientID %>").textContent = radius;
});
marker = new google.maps.Marker({
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: new google.maps.LatLng(latt, longg),
});
circle.setMap(map);
google.maps.event.addListener(marker, 'dragstart', function() {
circle.setMap(null);
});
google.maps.event.addListener(marker, 'dragend', function() {
latt= marker.getPosition().lat();
longg = marker.getPosition().lng();
circle.setCenter(new google.maps.LatLng(latt, longg));
document.getElementById("<%= lblLatitute.ClientID %>").textContent = latt;
document.getElementById("<%= lblLongitude.ClientID %>").textContent = longg;
circle.setMap(map);
});
}
function toggleBounce() {
}
</script>
答案 1 :(得分:0)
我认为您可能正在寻找事件center_changed
和radius_changed
。
您可以在google.maps.Circle
class文档页面的事件表中找到所有可用事件。