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