我支持我的评论,但这里是一个基本地图,它实现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>