顺利移动Google Maps标记

时间:2018-10-18 05:45:11

标签: javascript google-maps

我在Google地图上遇到一个问题,即当某些标记的坐标发生变化时,我的标记在地图上的移动速度太快了,有人可以帮助我如何使其平滑移动吗?谢谢!

<script type="text/javascript">
var values = [];
var map;
var markers = [];
function    initMap()
{
            var options = {
                center: {lat: -33.890542, lng: 151.274856},
                zoom: 4
            };
            map = new google.maps.Map(document.getElementById('map'), options);
            var count = 0; 
            setInterval(function() {
                getGps();
                for(var i = 0; i < markers.length; i++){
                        markers[i].setPosition(new google.maps.LatLng(values[count][1], values[count][2]));
                        count++;
                    }
            }, 1000);
}
function getGps() {
            xmlhttp.onreadystatechange=function() {    
                if( xmlhttp.readyState==4 && xmlhttp.status==200 ) {
                    var res = xmlhttp.responseText; 
                    var split1 = res.split("|");
                        for(var i = 0; i <= split1.length; i++){
                            var split2 = split1[i].toString().split(","); 
                            var holder1 = holder = [split2[0],split2[1],split2[2]];
                            values.push(holder1);
                            var marker1 = marker = new google.maps.Marker({map: map, icon: 'images/mapvehicle.png', draggable: true});
                            markers.push(marker1);
                        }   
                }
            };
            xmlhttp.open("POST","GpsPost",true);
            xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            xmlhttp.send();

}

0 个答案:

没有答案