本例是对winform中使用百度地图的简要介绍。百度地图目前支持android开发,ios开发,web开发,服务接口,具体可以参照'百度地图开放平台'。
【动态加载百度地图】涉及到的知识点:
WebBrowser控件,此控件是VS自带的控件,使用户可以在WinForm窗体中导航网页。主要用到Navigate函数,此函数将指定的统一资源定位符 (URL) 处的文档加载到浏览器新窗口或 System.Windows.Forms.WebBrowser 控件中。有关此控件的详细信息,请参照MSDN上详细说明。
百度地图JavaScript API,调用API在网页中显示百度地图。
效果图如下:

关于调用百度地图的Html代码如下:
1 2 3 4 5 6 9 10地图展示 11 41 42 43 44 45
关于WinForm调用Html的代码如下:
private void BaiduMap01_Load(object sender, EventArgs e)
2 {
3 //htm文件Copy到程序根目录
4 this.wbBaidu.Navigate(AppDomain.CurrentDomain.BaseDirectory + "Baidu01.htm",false);
5 }【加载静态图】涉及到知识点
调用百度的静态图接口
PictureBox VS自带的图片容器,表示用于显示图像的 Windows 图片框控件。
Codapp 扫码点餐小程序(含H5系统)下载Codapp 外卖点餐系统是一款专为快餐店、奶茶店、咖啡店、糕点店等商户打造的移动点餐解决方案,支持自提与外卖两种模式,可快速部署上线使用。 该系统支持微信、支付宝支付,并接入腾讯地图与百度地图,支持第三方配送(如达达)与商家自主配送,助力门店实现智能点单与订单管理。 功能特点: 微信小程序&H5移动端双端点餐:无需下载 App,直接扫码下单 支持多门店管理:一套系统可管理多家门
HttpWebRequest,HttpWebResponse 在WinForm中发送/接收 http请求。
Thread 为了不让界面卡死,采用在后台进程中调用。
将返回的字节流,转换成Image对象
效果图如下:

关于在WinForm程序中调用静态图API的代码如下:
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Net;
10 using System.IO;
11 using System.Threading;
12
13 namespace DemoSharp
14 {
15 public partial class BaiduMap02 : Form
16 {
17 public BaiduMap02()
18 {
19 InitializeComponent();
20 }
21
22 private void btnLoad_Click(object sender, EventArgs e)
23 {
24 //在线程中执行
25 Thread t = new Thread(new ThreadStart(InitMap));
26 t.Start();
27 }
28
29 private void InitMap() {
30 string url = "http://api.map.baidu.com/staticimage/v2?ak=AKCode需要申请&mcode=666666¢er=116.403874,39.914888&width=910&height=400&zoom=11";
31 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
32 request.Method = "GET";
33 HttpWebResponse response = request.GetResponse() as HttpWebResponse;
34 while (true)
35 {
36 if (response.StatusCode == HttpStatusCode.OK)
37 {
38 Image img = Image.FromStream(response.GetResponseStream());
39 this.pictureBox1.Image = img;
40 break;
41 }
42 Thread.Sleep(1000);
43 }
44 }
45 }
46 }后记:
调用百度地图相关功能时,需要先申请密钥(AK),个人开发学习使用手机进行注册即可。
以上就是C# 程序中嵌入百度地图的内容,更多相关内容请关注PHP中文网(www.php.cn)!










