marker dragend事件不起作用

时间:2013-04-27 20:12:25

标签: javascript maps marker

我有这个代码: 'dragend'事件的function()中的代码不执行,文档中的latFld和llgFld不更新 有什么帮助吗?

    var map;
    var marker;

    function initMap()
    {
    var latlng = new google.maps.LatLng(-27.780577, -64.279906);
    var myOptions = {
        zoom: 10,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    google.maps.event.addListener(map, "click", function(event) {
    if (marker) {marker.setMap(null)}

    marker = new google.maps.Marker({
        position: event.latLng,
        map: map,
        draggable:true
    });

    // display the lat/lng in your form's lat/lng fields
    document.getElementById("latFld").value = event.latLng.lat();
    document.getElementById("lngFld").value = event.latLng.lng();
    });

    google.maps.event.addListener(marker, 'dragend', function(){
    alert(marker.getPosition());
    document.getElementById("latFld").value = marker.getPosition().lat();
    document.getElementById("lngFld").value = marker.getPosition().lng();
    });
    }

0 个答案:

没有答案