日期:2014-05-16 浏览次数:20391 次
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>数据接口</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script>
<style>
.mapdiv{width:300px;height:300px;float:left;}
</style>
</head>
<body>
<div id="container" class="mapdiv" ></div>
<div id="results" class="mapdiv"></div>
<br/>
<FORM METHOD=POST ACTION="" name="frm1">
<INPUT TYPE="text" NAME="tbxuid" id="test1">
</form>
</body>
<script type="text/javascript">
var map = new BMap.Map("container");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 12);
var transit = new BMap.TransitRoute("北京市");
var test_polyline = new BMap.Polyline([
new BMap.Point(116.399, 39.910),
new BMap.Point(116.405, 39.920),
new BMap.Point(116.425, 39.920)
],
{strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5}
);
map.addOverlay(test_polyline);
transit.setSearchCompleteCallback(function(results){
if (transit.getStatus() == BMAP_STATUS_SUCCESS){ //利用getStatus()检测是否检索成功
var firstPlan = results.getPlan(0); //得到第一条方案
// 绘制步行线路
for (var i = 0; i < firstPlan.getNumRoutes(); i ++){
var walk = firstPlan.getRoute(i)
if (walk.getDistance(false) > 0){
// 步行线路有可能为0
map.addOverlay(new BMap.Polyline(walk.getPoints(), {strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5} ));
//错误提示 对象不支持此属性或方法行: 42字符: 1代码
//这里walk.getPoints()应该返回的直接是Polyline应该可以直接用作添加吧?
}
}
}
})
transit.search("中关村", "国贸桥");
</script>