Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 绘制路线历史_Javascript_Google Maps Api 3 - Fatal编程技术网

Javascript 绘制路线历史

Javascript 绘制路线历史,javascript,google-maps-api-3,Javascript,Google Maps Api 3,我需要显示由1000-2000(纬度/经度)点组成的路线 我试着这样做,但我不认为这是一个好的解决方案,显示路线为这么多的点;请建议最好的方法 function calcRoute() { var request = { origin:new google.maps.LatLng(37, -97), waypoints: [ { location:new google.maps.LatLng(39, -97)

我需要显示由1000-2000(纬度/经度)点组成的路线

我试着这样做,但我不认为这是一个好的解决方案,显示路线为这么多的点;请建议最好的方法

function calcRoute() {    
    var request = {
        origin:new google.maps.LatLng(37, -97),
        waypoints: [
        {
            location:new google.maps.LatLng(39, -97),
            stopover:false
        },{
            location:new google.maps.LatLng(32, -95),
            stopover:false
        }],
        destination:new google.maps.LatLng(37, -97),
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };    

    directionsService.route(request, function(response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
        }
    });
}

不必将整个结果传递给DirectionsRenderer,您可以使用对象的概览路径(简化),并将多段线直接添加到地图中,例如:

directionsService.route(request,plot);


function plot(result,status){
    if (status == google.maps.DirectionsStatus.OK) {
        for (var n = 0 ;n < result.routes.length ; n++ ){
            addLine(result.routes[n].overview_path);
        }
    }
}

function addLine(path){
    var line = new google.maps.Polyline ({
    path: path,
    map: map
    });
}
directionsService.route(请求、绘图);
功能图(结果、状态){
if(status==google.maps.directionstatus.OK){
对于(var n=0;n
最有可能的解决方案是,作为地图专家,您需要设计一种算法,在向用户显示足够信息的同时,不会将地图弄得乱七八糟,使信息变得模糊。映射中非常常见的问题。