基于C#调用的百度地图如何把地图上两点按照马路走向相连?

ji_xiang_wu 2018-02-01 08:05:54
具体的就是通过收到两个经纬度信息,在地图上定位两点,将这两点像导航里那样连接。
...全文
266 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2018-02-02
  • 打赏
  • 举报
回复
http://download.csdn.net/download/u011486249/8347231
zmyouren1983 2018-02-02
  • 打赏
  • 举报
回复
1、首先用一个html文件调用百度地图接口(主要注册一个序列号):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    <title>百度地图的Hello World</title>  
    <style type="text/css">  
        body, html, #allmap  
        {  
            width: 100%;  
            height: 100%;  
            overflow: hidden;  
            margin: 0;  
        }  
        #l-map  
        {  
            height: 100%;  
            width: 78%;  
            float: left;  
            border-right: 2px solid #bcbcbc;  
        }  
        #r-result  
        {  
            height: 100%;  
            width: 20%;  
            float: left;  
        }  
    </style>  
  
  
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=6c497f51c06477544e5fa6e9bd68f7c3"></script>  
  
  
</head>  
<body>  
    <div id="allmap">  
    </div>  
</body>  
</html>  
  
  
<script type="text/javascript">  
        // 百度地图API功能
	var map = new BMap.Map("allmap");
	map.centerAndZoom(new BMap.Point(116.404, 39.915), 15);

       function setdriving(x,y,z,w){        
        var myP1 = new BMap.Point(x,y);    //起点
	var myP2 = new BMap.Point(z,y);    //终点
	var driving2 = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});
	driving2.search(myP1, myP2);
       }  

</script>  
2、建立一个Winform项目,用一个WebBrower控件查看html文件、调用JavaScript代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                webBrowser1.Url = new Uri("http://127.0.0.1/route.html");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }  
  
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            webBrowser1.Document.InvokeScript("setdriving", new object[] { 116.380967, 39.913285, 116.424374, 39.914668 }); 
        }

    }
}

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧