1、首先用一个html文件调用百度地图接口(主要注册一个序列号):
百度地图的Hello World
2、建立一个Winform项目,用一个WebBrower控件查看html文件、调用JavaScript代码
using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace BaiDuMap { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { try { //webBrowser1.Url = new Uri("http://www.2345.com"); //这个文件于可执行文件放在同一目录 webBrowser1.Url = new Uri(Path.Combine(Application.StartupPath, "GoogleMap.htm")); } catch (Exception ex) { MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { //这里传入x、y的值,调用JavaScript脚本 webBrowser1.Document.InvokeScript("setLocation", new object[] { 121.504, 39.212 }); } } }