[c#]代码库
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//新添加命名空间
using System.Net;
using System.IO;
using System.Security.Permissions; //交互JS
namespace MapWinForms
{
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//载入加载地图
private void Form1_Load(object sender, EventArgs e)
{
//本地文件 MapWinForms\bin\Debug
string url = Application.StartupPath + "\\BaiMapJS.html";
string file = <a target=_blank href="file:///E:\\WinFormBaiduMap\\test.html">file:///E:\\WinFormBaiduMap\\test.html</a>;
webBrowser1.ScriptErrorsSuppressed = true; //屏蔽js相关错误
webBrowser1.Navigate(url); //导航显示本地HTML文件
}
//城市搜索
private void button1_Click(object sender, EventArgs e)
{
/**
* 参考资料:
* http://bbs.csdn.net/topics/390935011
* http://www.sufeinet.com/thread-7897-1-1.html
*/
//C#调用JS函数
string city;
if (comboBox1.SelectedIndex == -1)
{
city = "北京";
}
else
{
city = comboBox1.SelectedItem.ToString();
}
webBrowser1.Document.InvokeScript("LoadMap", new object[] { city });
}
//车间搜索
private void button2_Click(object sender, EventArgs e)
{
string city;
if (comboBox1.SelectedIndex == -1)
{
city = "北京";
}
else
{
city = comboBox1.SelectedItem.ToString();
}
webBrowser1.Document.InvokeScript("SearchCarMap", new object[] { city });
}
//附近热点搜索
private void button3_Click(object sender, EventArgs e)
{
string city;
if (comboBox1.SelectedIndex == -1)
{
city = "北京";
}
else
{
city = comboBox1.SelectedItem.ToString();
}
string key;
if (comboBox2.SelectedIndex == -1)
{
key = "学校";
}
else
{
key = comboBox2.SelectedItem.ToString();
}
webBrowser1.Document.InvokeScript("SearchNearbyMap", new object[] { city, key });
}
//当前位置定位
private void button4_Click(object sender, EventArgs e)
{
webBrowser1.Document.InvokeScript("LocateMyPlcae", new object[] { });
}
//附近餐馆
private void button5_Click(object sender, EventArgs e)
{
webBrowser1.Document.InvokeScript("GetResMyPlace", new object[] { });
}
//导航
private void button6_Click(object sender, EventArgs e)
{
webBrowser1.Document.InvokeScript("RouteMyPlace", new object[] { });
}
}
}