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

Google maps 如何在谷歌地图中移动标记?,google-maps,google-maps-api-3,google-maps-markers,geocoding,Google Maps,Google Maps Api 3,Google Maps Markers,Geocoding,我想自动移动一个标记到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: 1

我想自动移动一个标记到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
        });

    }
}
我该怎么做


谢谢。

如果要在聚合标记后移动标记,请执行以下操作:

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

缺少一个参数“draggable”并设置为TRUE,默认情况下为FALSE。

只需使用以下参数移动标记:

function moveMarker( map, marker ) {

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

};

我终于找到了解决办法。 我没有使用地址的反向地理编码,而是在DB中获取坐标,然后像这样进行移位:

var coordinates_str, actual_lat, actual_lng, adjusted_lat, adjusted_lng;

actual_lat = adjusted_lat = '<?php echo $lat ?>';
actual_lng = adjusted_lng = '<?php echo $lng ?>';

adjusted_lat = parseFloat(actual_lat) + (Math.random() -.5) / 25;
adjusted_lng = parseFloat(actual_lng) + (Math.random() -.5) / 25;
coordinates_str = String(adjusted_lat) + String(adjusted_lng);

var coordonnees = new google.maps.LatLng(adjusted_lat, adjusted_lng);

var centerMap = new google.maps.LatLng(adjusted_lat, adjusted_lng);
var坐标,实际纬度,实际lng,调整纬度,调整lng;
实际水平=调整水平=“”;
实际液化天然气=调整后的液化天然气=“”;
调整后的浮动=parseFloat(实际浮动)+(Math.random()-.5)/25;
调整后的液化天然气=parseFloat(实际液化天然气)+(Math.random()-.5)/25;
坐标=管柱(调整后的管柱)+管柱(调整后的管柱);
var coordones=new google.maps.LatLng(调整后的,调整后的);
var centerMap=new google.maps.LatLng(调整后的,调整后的);

谢谢您的帮助。

x公里的地方?朝哪个方向?你尝试了什么?谢谢你的回答。距离标记的原始位置随机x公里。@Beno,你能再解释一下你想要达到的目标吗?加载贴图时,是要将标记从位置a移动到位置B,还是只对其设置动画?我只想在不设置动画的情况下将标记从位置a移动到位置B。这是一个房地产网站,我不想显示房地产的真实位置。谢谢Martin.Like?谢谢,但是我如何从使用geocoder.geocoder({'address':address},function(results,status){if(status==google.maps.GeocoderStatus.OK){map.setCenter(results[0].geometry.location);}多谢智者们,但我希望在将标记放在地图上之前自动移动标记