功能如下:打开时自动定位到当前位置(浏览器可能会屏蔽自动定位功能,建议手机查看,或直接打开地址:http://1.jingcode.applinzi.com/test2.html),输入目的地点击搜索后,显示当前位置和目的地之间的线路图。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
#allmap{width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
header{margin: 5px auto;font-size: 16px;}
.typein{width: 90px;height: 16px;font-size: 16px;}
/*.btn{color:#fff;height: 25px;}*/
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=6VArBpbbbMjBVP22TflHkpSq"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
<title>路线查询</title>
</head>
<body>
<header>
<label for="start">起点:<input type="text" placeholder="请输入起点" class="typein" ).value;
//从定位地点到终点
//search(new BMap.Point(lng, lat),zhongdian,BMAP_DRIVING_POLICY_LEAST_DISTANCE);
//从输入的起点到终点
search(qidian,zhongdian,BMAP_DRIVING_POLICY_LEAST_DISTANCE);
function search(start,end,route){
var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true},policy: route});
driving.search(start,end);
}
}
</script>
相关文章: