Google maps v3 draggable marker

前端 未结 4 506
忘了有多久
忘了有多久 2021-01-29 23:37

I\'m new in google maps, and I\'m trying to learn it.

marker = new google.maps.Marker(
{
     map:map,
     draggable:tru         


        
4条回答
  •  离开以前
    2021-01-30 00:01

    Finally I found the answer:

    marker = new google.maps.Marker(
    {
        map:map,
        draggable:true,
        animation: google.maps.Animation.DROP,
        position: results[0].geometry.location
    });
    google.maps.event.addListener(marker, 'dragend', function() 
    {
        geocodePosition(marker.getPosition());
    });
    
    function geocodePosition(pos) 
    {
       geocoder = new google.maps.Geocoder();
       geocoder.geocode
        ({
            latLng: pos
        }, 
            function(results, status) 
            {
                if (status == google.maps.GeocoderStatus.OK) 
                {
                    $("#mapSearchInput").val(results[0].formatted_address);
                    $("#mapErrorMsg").hide(100);
                } 
                else 
                {
                    $("#mapErrorMsg").html('Cannot determine address at this location.'+status).show(100);
                }
            }
        );
    }
    

提交回复
热议问题