Google Map API路线请求限制 [英] Google Map API Route Request limit

查看:115
本文介绍了Google Map API路线请求限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究我的项目,我需要计算Google地图中23条驾车路线的距离。我在这里有代码。 Lat和lng已经在js中建立了,但我只能在网络中返回10个路由距离。我检查谷歌地图api的限制,但我没有看到路线方向只有10个限制。我附上代码....我想知道是否有人可以帮我弄清楚.....非常感谢!

 <!DOCTYPE html> 
< html>
< html>
< head>< meta name =viewportcontent =initial-scale = 1.0,user-scalable = no/>< meta http-equiv =content-typecontent =text / html; charset = UTF-8/>
< title> Google Maps JavaScript API v3示例:Directions Waypoints< / title>
< link href =http://code.google.com/apis/maps/documentation/javascript/examples/default.css =stylesheettype =text / css/>
< script type =text / javascriptsrc =http://maps.google.com/maps/api/js?sensor=false>
< / script>
< link type =text / css =stylesheethref =https://s3.amazonaws.com/GTFS/style.cssmedia =all/>

< / head>

< body id =mainBodyonload =initialize()>
< div id =headerImage>
< img src =https://s3.amazonaws.com/GTFS/brt.jpgheight =100width =180/>
< / div>

< header id =mainHeader>
< hgroup id =mainHeaderGroup>
< h1> GTFS数据可视化&应用与LT; / H1>
< br />
< br />
< br />
< / hgroup>
< / header>
< div id =contentContainer>
< div id =map_canvasstyle =width:0%; height:0%;>
< / div>
< br />
< p id =demo>
< / p>
< script type =text / javascript>
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

函数initialize(){
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(-40.321,175.54);
var myOptions = {
zoom:6,
mapTypeId:google.maps.MapTypeId.ROADMAP,
center:chicago
}
map = new google .maps.Map(document.getElementById(map_canvas),myOptions);
directionsDisplay.setMap(map);
calcRoute();


函数calcRoute(){
var locations = [
['location1',30.27361,-97.69835,4],
['location2 ',30.273206,-97.700665,5],
['location3',30.272939,-97.70225,3],
['location4',30.272556,-97.704568,2],
[',
['location6',30.272329,-97.708247,5],
['location7',30.271236,-97.710649,3],
[位置5',30.272509,-97.706226,4] 'location8',30.270419,-97.715,2],
['location8',30.270096,-97.717001,4],
['location9',30.269698,-97.719604,5],
['location10',30.269427,-97.72125,3],
['location11',30.268978,-97.724138,2],
['location12',30.270096,-97.717001,4],
['location13',30.269698,-97.719604,5],
['location14',30.269427,-97.72125,3],
['location15',30.268978,-97.724138,2],
['location16',30.268756,-97.725507,1],
['location17',30.268704,-97.727634, 2],
['location18',30.26956,-97.729989,4],
['location19',30.269995,-97.731193,5],
['location20',30.270893,-97.734212 ,3],
['location21',30.27116,-97.738825,2],
['location22',30.271811,-97.741229,2],
['location23',30.268756, - 97.725507,1]
];

var i = 0;
for(i = 0; i< locations.length - 1; i ++){
var start = new google.maps.LatLng(locations [i] [1],locations [i] [2 ]);
var end = new google.maps.LatLng(locations [i + 1] [1],locations [i + 1] [2]);
var request = {
origin:start,
destination:end,
travelMode:google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request,function(response,status){
if(status == google.maps.DirectionsStatus.OK){
directionsDisplay.setDirections(response);
var route = response.routes [0];
document.getElementById(demo)。innerHTML + =< strong>< br />< hr />+ route.legs [0 ] .distance.text +< / strong>;
}
});
}
}
< / script>
< / div>
< / body>
< / html>


解决方案

免费API有8个航点的限制2个端点给出10)。付费API允许23个航点。



源自文档


允许的最大航点为8,加上出发地和目的地。 Maps API for Business
客户可以使用23个航点,加上出发地和目的地。您可以尝试将多个请求链接在一起,例如 //www.geocodezip.com/v3_directions_multipleWayPts_CustomMrkrs_busRoute.htmlrel =nofollow>这个,但要小心DirectionsService受费率限制和配额限制,所以这可能不会总是有效。



带您积分的例子


I am working on my project in which I need to calculate distances of 23 driving routes in Google map. I have the code here. The Lat and lng are already set up in js but I only get 10 route distances back in the web. I check the limitations of google maps api but I don't see only 10 limitations for the route direction. I attached the code.... I am wondering whether anybody can help me figure out.....Thank you so much!

<!DOCTYPE html>
<html>
<html>
    <head><meta name="viewport" content="initial-scale=1.0, user-scalable=no"/><meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
        <title>Google Maps JavaScript API v3 Example: Directions Waypoints</title>
        <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
        </script>
        <link type="text/css" rel="stylesheet" href="https://s3.amazonaws.com/GTFS/style.css" media="all" />

    </head>

<body id="mainBody" onload="initialize()">
<div id="headerImage">
<img src="https://s3.amazonaws.com/GTFS/brt.jpg" height="100" width="180" />
</div>

    <header id="mainHeader">
        <hgroup id="mainHeaderGroup">
            <h1>GTFS Data Visualization & Application</h1>
            <br />
            <br />
            <br />
        </hgroup>
    </header>
    <div id="contentContainer" >
        <div id="map_canvas" style="width:0%;height:0%;">
        </div>
        <br />
        <p id="demo">
</p>
        <script type="text/javascript">
    var directionDisplay;
    var directionsService = new google.maps.DirectionsService();
    var map;

    function initialize() {
        directionsDisplay = new google.maps.DirectionsRenderer();
        var chicago = new google.maps.LatLng(-40.321, 175.54);
        var myOptions = {
            zoom: 6,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            center: chicago
        }
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        directionsDisplay.setMap(map);
        calcRoute();
    }

    function calcRoute()  {
         var locations = [
  ['location1', 30.27361,-97.69835, 4],
  ['location2', 30.273206,-97.700665, 5],
  ['location3',30.272939,-97.70225, 3],
  ['location4', 30.272556,-97.704568, 2],
    ['location5', 30.272509,-97.706226, 4],
  ['location6', 30.272329,-97.708247, 5],
  ['location7', 30.271236,-97.710649, 3],
  ['location8', 30.270419,-97.715, 2],
    ['location8', 30.270096,-97.717001, 4],
  ['location9', 30.269698,-97.719604, 5],
  ['location10', 30.269427,-97.72125, 3],
  ['location11', 30.268978,-97.724138, 2],
   ['location12', 30.270096,-97.717001, 4],
  ['location13', 30.269698,-97.719604, 5],
  ['location14', 30.269427,-97.72125, 3],
  ['location15', 30.268978,-97.724138, 2],
  ['location16', 30.268756,-97.725507, 1],
    ['location17',30.268704,-97.727634, 2],
  ['location18', 30.26956,-97.729989, 4],
  ['location19', 30.269995,-97.731193, 5],
  ['location20', 30.270893,-97.734212, 3],
  ['location21', 30.27116,-97.738825, 2],
   ['location22', 30.271811,-97.741229, 2],
  ['location23', 30.268756,-97.725507, 1]
];   

var i=0;
for (i = 0; i < locations.length - 1; i++) {
var start = new google.maps.LatLng(locations[i][1], locations[i][2]);
var end = new google.maps.LatLng(locations[i + 1][1], locations[i + 1][2]);
var request = {
origin : start,
destination : end,
travelMode : google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request,function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var route = response.routes[0];
document.getElementById("demo").innerHTML += "<strong> <br /> <hr />"+     route.legs[0].distance.text + "</strong>";
}
});
}
}
</script>
</div>
</body>
</html>

解决方案

The free API has a limitation of 8 waypoints (plus the 2 endpoints give 10). The paid API allows 23 waypoints.

from the documentation

The maximum allowed waypoints is 8, plus the origin, and destination. Maps API for Business customers are allowed 23 waypoints, plus the origin, and destination. Waypoints are not supported for transit directions.

You can try chaining multiple requests together like this, but beware the DirectionsService is subject to rate limits and quotas, so that might not always work.

example with your points

这篇关于Google Map API路线请求限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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