本文介绍了使用Google Maps API v2从超过25点的loadFromWaypoints加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。我知道在Google地图中, GDirections.loadFromWayPoints 的限制为25 GLatLng 对象。我想要的是建立一个300点的路线。



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

有什么建议?



这是我的ajax函数,它试图完成我所描述的内容:

 函数ajaxFunction(url){
var ajaxRequest; //使Ajax成为可能的变量!

尝试{
// Opera 8.0+,Firefox,Safari
ajaxRequest = new XMLHttpRequest();
catch(e){
// Internet Explorer浏览器
尝试{
ajaxRequest = new ActiveXObject(Msxml2.XMLHTTP);
} catch(e){
try {
ajaxRequest = new ActiveXObject(Microsoft.XMLHTTP);
} catch(e){
//出错了
alert(Your browser broke!);
返回false;


$ b //创建一个函数,接收从服务器发送的数据
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(^); (var i = 0; i





$ b 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 ++;



$ b / * 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);


解决方案

PathPolyline可以完成这项工作: a href =https://github.com/spinningcode/PathPolyline =nofollow> https://github.com/spinningcode/PathPolyline



从其描述中可以看出:

有一些使用说明和演示代码,您可能会发现它们很有帮助。


I have a problem. I know that in google maps, the GDirections.loadFromWayPoints has limit of 25 GLatLng objects. What I want is to make a route of, say, 300 points.

How can I do that? The solution I thought of was using arrays of 25 positions, and then call loadFromWaypoints, create another array of 25 positions, and call loadFromWayPoints and so on, but when I do this, I can just see the first array in my map.

Any suggestions?

Here is my ajax function which attempts to do what I've described:

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);
}
解决方案

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

From its description:

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

这篇关于使用Google Maps API v2从超过25点的loadFromWaypoints加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 19:11