使用Google Maps API v2从超过25点的loadFromWaypoints加载 [英] loadFromWaypoints with more than 25 points using Google Maps API v2

查看:104
本文介绍了使用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 <(rta.length)-1; 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



从其描述中可以看出:


PathPolyline是一个简单的库,可用于获取最大路点数的25点限制使用GDirection.loadFromWaypoints方法(Google Map API V2)。


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


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:

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆