如何在Google地图中移动标记?

Ben*_*eno 0 google-maps geocoding google-maps-api-3 google-maps-markers

我想自动将标记移动到x公里.

这是我的代码:

geocoder.geocode({'address': address}, function(results, status) {

    if (status == google.maps.GeocoderStatus.OK) {

        var myMap = new google.maps.LatLng(-34.397, 150.644);
        var myOptions = {
            zoom: 11,
            center: myMap,
            scrollwheel: false,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        var map = new google.maps.Map(document.getElementById("show_map"), myOptions);
        map.setCenter(results[0].geometry.location);

        var marker = new google.maps.Marker({
            position: results[0].geometry.location,
            flat: false,
            map: map
        });

    }
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

谢谢.

Lan*_*kea 5

只需移动您的标记:

function moveMarker( map, marker ) {

    marker.setPosition( new google.maps.LatLng( Lat, Lng) );
    map.panTo( new google.maps.LatLng( Lat, Lng) );

};
Run Code Online (Sandbox Code Playgroud)