查询泰和城市的公交路线
详请代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>获取公交站点坐标</title>
<style type="text/css">
html,body{ height: 100%;}
#results,#coordinate{ display: inline-block; width: 45%; min-height: 200px; border:1px solid #e4e4e4; vertical-align: top;}
</style>
<script src="http://api.map.baidu.com/api?v=1.3" type="text/javascript"></script>
</head>
<body>
<p><label for="busId">公交线路:</label><input type="text" value="521" id="busId" /><input type="button" id="btn-search" value="查询" /></p>
<div id="results"></div>
<div id="coordinate"></div>
<script type="text/javascript">
(function(){
var tempVar;
var busline = new BMap.BusLineSearch('泰和',{
renderOptions:{panel:"results"},
onGetBusListComplete: function(result){
if(result) {
tempVar = result;
busline.getBusLine(result.getBusListItem(0));
}
},
onBusLineHtmlSet : function(){
try{
getCoordinate(tempVar);
}catch(e){
}
}
});
function getCoordinate(result){
var coordinate = document.getElementById("coordinate");
var stations = result['0']._stations;
var html = [];
stations.forEach(function(item){
html.push('<li>' + item.name + ' ' + item.position.lng + ' ' + item.position.lat + '</li>');
});
coordinate.innerHTML = '<ul>' + html.join('') + '</ul>';
}
document.getElementById('btn-search').onclick = function(){
busline.getBusList(document.getElementById("busId").value);
}
})();
</script>
</body>
</html>