0
這是我測試的例子和我試圖找出的代碼的鏈接。 http://www.gaiser-vfx.com/media/maptest.html谷歌地圖標記事件監聽器不工作
<div id="googleMap">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script>
<div id="map_canvas" style="width:100%; height:300px"></div>
<script>
var noLocation = new google.maps.LatLng(52.1307, -3.78371);
var initialLocation;
var browserSupportFlag = new Boolean();
var map;
var myOptions = {
zoom: 6,
draggable: true,
minZoom: 0,
maxZoom: 20,
disableDefaultUI: true,
zoomControl: true,
scrollwheel: true,
disableDoubleClickZoom: true,
mapTypeId: google.maps.MapTypeId.false
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map, 'bounds_changed', function() {
var center = map.getCenter();
var zoomLevel = map.getZoom();
$('#LocationLatitude').val(center.lat().toFixed(5));$('#LocationLongitude').val(center.lng().toFixed(5));$('#LocationZoom').val(zoomLevel);});
var poly
var path = new google.maps.MVCArray;
poly = new google.maps.Polygon({
strokeWeight: 3,
fillColor: '#5555FF'
});
poly.setMap(map);
poly.setPaths(new google.maps.MVCArray([path]));
google.maps.event.addListener(map, 'click', addPoint);
function addPoint(event) {
path.insertAt(path.length, event.latLng);
var marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
markers.push(marker);
marker.setTitle("#" + path.length);
google.maps.event.addListener(marker, 'click', function() {
marker.setMap(null);
for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
markers.splice(i, 1);
path.removeAt(i);
});
google.maps.event.addListener(marker, 'dragend', function() {
for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
path.setAt(i, marker.getPosition());
}
);
}
</script>
`
這是我試圖效仿的榜樣。
http://gmaps-samples-v3.googlecode.com/svn/trunk/poly/poly_edit.html
我的一個代碼和例子之間的主要差異是在本例中使用的初始化函數調用,而我只是想在加載網頁載入我的。在我的地圖測試中,我可以在地圖上放置標記並將它們移動並移動它們,但是每個標記上將poly更新爲新標記點的功能以及刪除每個標記的功能似乎都不起作用。
參見:http://stackoverflow.com/questions/10854431/how-to-when-marker -is-點擊-點心的地圖和放映-A-大DIV-INSTEAD-OF-AN-IN/10854743#10854743 –