输入起点和终点位置(全国范围):
输入起点和终点位置(本市范围):
就是一个html页面调用百度地图API
使用webBrowser控件调用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%;
margin: 0;
font-family: "微软雅黑";
}
#l-map {
height: 320px;
width: 100%;
}
#r-result, #r-result table {
width: 100%;
}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你的key"></script>
<title>驾车导航的结果面板</title>
</head>
<body>
<div> 起点:<input type="text" id="txtStart" width="10" /> 终点:<input type="text" id="txtStop" width="10" /> <input type="button" id="btnSerach" value="查询" οnclick="show()" /></div>
<div id="l-map"></div>
<div id="r-result"></div>
</body>
</html>
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("l-map");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 14);
map.enableScrollWheelZoom(true);
function show() {
var map = new BMap.Map("l-map");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 10);
map.enableScrollWheelZoom(true);
var driving = null;
var start = document.getElementById("txtStart").value;
var stop = document.getElementById("txtStop").value;
driving = new BMap.DrivingRoute(map, { renderOptions: { map: map, panel: "r-result", autoViewport: true } });
driving.search(start, stop);
}
</script>
窗体调用html页面方法
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.Navigate(@"E:\项目\委托Test\百度地图路线规划\index.html");
}
}