我支持我的評論,但這裏是一個基本地圖,它使用地理編碼器實現了center_changed
(帶標記)和dragend
。
在IE9中,Chrome 19和Firefox 13的dragend
事件僅在每次拖動時觸發一次。你會注意到,center_changed
被激發很多次,即使拖動沒有完成。這就是爲什麼我相信你的FindReverseGeocode
方法在FixedMarkerInCenter
中被調用。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' type='text/javascript'></script>
<script type="text/javascript"></script>
</head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
var geocoder;
function initialize()
{
var latlng = new google.maps.LatLng(47.6059399181561, 14.747812500000007);
map = new google.maps.Map(document.getElementById('map'), {
zoom:6,
center:latlng,
mapTypeId:google.maps.MapTypeId.HYBRID
});
google.maps.event.addListener(map, 'center_changed', placeMarker);
google.maps.event.addListener(map, 'dragend', reverseLookup);
geocoder = new google.maps.Geocoder();
}
function placeMarker()
{
var center = map.getCenter();
marker = new google.maps.Marker({
map:map,
position: center
});
}
function reverseLookup()
{
geocoder.geocode({'latLng': map.getCenter()}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
document.getElementById('area').value =
results[results.length-1].formatted_address + " " +
map.getCenter() + "\r\n" + document.getElementById('area').value;
}
});
}
</script>
<body onLoad="initialize()">
<div id="map" style="width: 800px; height: 350px;"></div>
<textarea id='area' cols='80' rows='5'></textarea>
</body>
</html>
我猜你在'FixexMarkerInCenter'和'FixedMarkerInCenterZoom'中調用了'FindReverseGeocode',這導致了很多對'FindReverseGeocode'的調用。 –