调用 百度公交查询API

admin2020-12-15  1.1K+

import console;
import web.rest.jsonLiteClient;

var http = web.rest.jsonLiteClient();
var baiduMap = http.declareApi("http://api.map.baidu.com/direction/v1?output=json&ak=peTf6C5sK9Wcgum9L9Gc7pER&mode={transit}&region={region}&origin={origin}&destination={destination}")

//查询公交线路
var data = baiduMap.transit["北京"]["上地五街"]["北京大学"]()

if( data && data.status == 0 ){
for(i=1;#data.result.routes;1){
var scheme = data.result.routes[i].scheme[1]
console.log( "总里程:",math.round(scheme.distance / 1000,2) + "公里" )
console.log( "总耗时",math.round(scheme.duration / 60,2) + "分钟" )

for(i=1;#scheme.steps;1){
var step = scheme.steps[i][1];
if( type(step.vehicle ) == type.table ) console.log( "",step.vehicle.name + "-->" + step.vehicle.end_name )
console.log("-->", "里程", math.round(step.distance / 1000,2) + "公里" )
console.log("-->", "耗时", math.round(step.duration / 60,2) + "分钟" )
}
console.log( "","终点站")
console.more( 1 )
}
}
转载请注明原文地址: http://www.aardio.net/read-72.html
最新回复(0)
API
api调用操作