C# 调用百度地图web服务API

1.关于百度提供的接口中的方法的实用,这里有很多官方提供的DEMO(http://developer.baidu.com/map/jshome.htm).

2.为了能与JS交互,首先引入using System.Security.Permissions;

                在命名空间里添加:

        [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]  
        [System.Runtime.InteropServices.ComVisibleAttribute(true)]   

3.初始化webBrowser组件

        private void Form1_Load(object sender, EventArgs e)
        {
             string str_url = Application.StartupPath + "\\IndexMap.html";
             Uri url = new Uri(str_url);  
             webBrowser1.Url = url;  
             webBrowser1.ObjectForScripting = this;
             timer1.Enabled = true;  
        }

4.获取坐标

        private void timer1_Tick(object sender, EventArgs e)
        {
            try  
           {  
               string tag_lng = webBrowser1.Document.GetElementById("mouselng").InnerText;  
               string tag_lat = webBrowser1.Document.GetElementById("mouselat").InnerText;  
               double dou_lng, dou_lat;  
               if (double.TryParse(tag_lng, out dou_lng) && double.TryParse(tag_lat, out dou_lat))  
               {  
                   this.toolStripStatusLabel1.Text ="当前坐标:"+ dou_lng.ToString("F5") + "," + dou_lat.ToString("F5");  
               }  
           }  
           catch (Exception ee)  
           { 
               MessageBox.Show(ee.Message); 
           }  
        }

5.一些方法的调用

            1. webBrowser1.Document.InvokeScript("drawRec");//画矩形

            2.webBrowser1.Document.InvokeScript("drawCircle");//画圆形

            3.webBrowser1.Document.InvokeScript("openGetDistance");//测距

            .........

            .........

6.百度提供的DEMO

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值