Google Maps API - 折线符合道路限制

时间:2013-11-01 17:34:48

标签: javascript google-maps polyline

我正在修建几条折线。下面是2个代码。超过15条折线对齐,我有以下错误:“路线请求失败:OVER_QUERY_LIMIT”。

因此,我想找到一个解决方案。其中之一就是将所有这些信息放入我的计算机缓存中,所以我从谷歌地图中得到的唯一信息就是地图。这可能吗?

你知道其他一些解决方案吗?

//Circuit CHL1C1

CHL1C1 = [
    new google.maps.LatLng(-22.91401,-68.192237),
    new google.maps.LatLng(-23.226361,-67.064938)
    ];

var traceCHL1C1 = new google.maps.Polyline({
    path: CHL1C1,
    strokeColor: "red",
    strokeOpacity: 1.0,
    strokeWeight: 4
});

var serviceCHL1C1 = new google.maps.DirectionsService(),traceCHL1C1,snap_pathCHL1C1=[];
traceCHL1C1.setMap(map);
for(j=0;j<CHL1C1.length-1;j++){
    serviceCHL1C1.route({origin: CHL1C1[j],destination: CHL1C1[j+1],travelMode: google.maps.DirectionsTravelMode.DRIVING},function(result, status) {
        if(status == google.maps.DirectionsStatus.OK) {
            snap_pathCHL1C1 = snap_pathCHL1C1.concat(result.routes[0].overview_path);
            traceCHL1C1.setPath(snap_pathCHL1C1);
        } else alert("Directions request failed: "+status);        
    });
}




//Circuit CHL1C2

CHL1C2 = [
    new google.maps.LatLng(-22.898988,-68.198154),
    new google.maps.LatLng(-22.337195,-68.016747),
    new google.maps.LatLng(-22.443062,-68.899408)
];

var traceCHL1C2 = new google.maps.Polyline({
    path: CHL1C2,
    strokeColor: "green",
    strokeOpacity: 1.0,
    strokeWeight: 4
});

var serviceCHL1C2 = new google.maps.DirectionsService(),traceCHL1C2,snap_pathCHL1C2=[];
traceCHL1C2.setMap(map);
for(j=0;j<CHL1C2.length-1;j++){
    serviceCHL1C2.route({origin: CHL1C2[j],destination: CHL1C2[j+1],travelMode: google.maps.DirectionsTravelMode.DRIVING},function(result, status) {
        if(status == google.maps.DirectionsStatus.OK) {
            snap_pathCHL1C2 = snap_pathCHL1C2.concat(result.routes[0].overview_path);
            traceCHL1C2.setPath(snap_pathCHL1C2);
        } else alert("Directions request failed: "+status);        
    });
}

2 个答案:

答案 0 :(得分:0)

如果我错了,请纠正我,但免费API最多有8个航点。

答案 1 :(得分:0)

免费API最多有8个航路点。但是,根据您要做的事情,您可以通过创建折线数组并为数组中的每个元素调用一次指向服务来解决此限制。