Dowemo
0 0 0 0

First, write down the following code in the html file;

<!DOCTYPE html><html><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/><metaname="viewport"content="initial-scale=1.0, user-scalable=no"/><styletype="text/css">body, html, #allmap{
 width:100%;
 height:100%;
 overflow: hidden;
 margin:0;
 font-family: 微软雅黑;
 }</style><scripttype="text/javascript"src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"></script>//<scripttype="text/javascript"src="MarkerClusterer_min.js"></script>//<scripttype="text/javascript"src="LuShu_min.js"></script><title>获取地图经纬度</title></head><body><divid="mouselng"style="visibility:hidden"></div><divid="mouselat"style="visibility:hidden"></div><divid="allmap"></div></body></html><scripttype="text/javascript">var map = new BMap.Map("allmap"); 
 var point = new BMap.Point(116.404, 39.915);
 map.centerAndZoom(point, 8);//窗体加载之后初始的坐标点和放缩倍数 map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放//map.centerAndZoom(); map.enableKeyboard(true);//开启键盘控制 map.addEventListener("mousemove", GetlngAndlat);//添加鼠标移动获取经纬度功能//获取坐标functionGetlngAndlat(e) {if (e.point.lng!= null) {
 document.getElementById("mouselng").innerHTML = e.point.lng;
 document.getElementById("mouselat").innerHTML = e.point.lat;
 }
 }
 </script>

Add a timer control, and then write the following function in the form startup method in the cs file:

#region 窗体加载事件privatevoidF_HistoricalTraceControl_Load(object sender, EventArgs e)
 {
 string str_url = Application.StartupPath + "定义的HTML文件名称.html";//放在debug文件夹下 Uri url = new Uri(str_url);
 HistoricalTraceWebBrowser.Url = url;
 HistoricalTraceWebBrowser.ObjectForScripting = this;
 latLngTimer.Enabled = true;//timer控件 }
 #endregion

Add a timer event, as follows:

#region 鼠标移动获取地图上点的经纬度privatevoidlatLngTimer_Tick(object sender, EventArgs e)
 {
 try {
 //将html中获取的坐标交互string tag_lng = HistoricalTraceWebBrowser.Document.GetElementById("mouselng").InnerText;
 string tag_lat = HistoricalTraceWebBrowser.Document.GetElementById("mouselat").InnerText;
 double dou_lng, dou_lat;
 if (double.TryParse(tag_lng, out dou_lng) && double.TryParse(tag_lat, out dou_lat))
 {
 //显示当前点位置,根据自己的要求将经纬度显示出来 sSecItem.Caption = string.Format("经度:{0}, 纬度:{1}", dou_lng.ToString("F5"), dou_lat.ToString("F5"));
 }
 }
 catch (Exception ee)
 {
 //MessageBox.Show(ee.Message); }
 }
 #endregion



Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs