5

我有个问题。我知道在谷歌地图中,GDirections.loadFromWayPoints​​有 25 个GLatLng对象的限制。我想要的是制作一条 300 点的路线。

我怎样才能做到这一点?我想到的解决方案是使用 25 个位置的数组,然后调用 loadFromWaypoints,创建另一个 25 个位置的数组,然后调用 loadFromWayPoints 等等,但是当我这样做时,我只能看到地图中的第一个数组。

有什么建议么?

这是我的 ajax 函数,它试图做我所描述的:

function ajaxFunction(url){
    var ajaxRequest;  // The variable that makes Ajax possible!

    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){

        var dirMap = new GMap2(document.getElementById("map"));
        if(ajaxRequest.readyState == 4){

           var cnt = 0;
           var cen = 0;
           var rta = ajaxRequest.responseText.split("^");

           for (var i = 0; i<(rta.length) -1; i++)

           {

            var reg = rta[i].split("$");
            var lat = reg[0];
            var lng = reg[1];

            if (cnt == 24) {

                var marker = new GMarker(arrayWP[1]);
                dirMap.addOverlay(marker);
                if (cen == 0) {
                   dirMap.setCenter(arrayWP[0], 12);
                   cen = 1;
                }
                dirMap.setUIToDefault();

                directions = new GDirections(dirMap);
                directions.loadFromWaypoints(arrayWP);
                arrayWP[0] = new GLatLng(lat,lng);
                cnt = 1;

            }
            else
            {
                arrayWP[cnt] = new GLatLng(lat,lng);
                cnt++;
            }

           }

         /*  if (cen == 0) {
                var marker = new GMarker(arrayWP[1]);
                dirMap.addOverlay(marker);
                if (cen == 0) {
                   dirMap.setCenter(arrayWP[0], 12);
                   cen = 1;
                }
                dirMap.setUIToDefault();

                directions = new GDirections(dirMap);
                directions.loadFromWaypoints(arrayWP);
           }*/

        }     
    }                             

    ajaxRequest.open("GET", url, true);
    ajaxRequest.send(null);
}
4

1 回答 1

4

PathPolyline does the job: https://github.com/spinningcode/PathPolyline

From its description:

PathPolyline is a simple library that can be used to get around the 25 points limitation on the maximum number of waypoints with GDirection.loadFromWaypoints method (Google Map API V2).

The readme file has some usage instructions and demonstration code which you may find helpful.

于 2012-01-30T04:33:04.343 回答