This example is a brief introduction to the use of Baidu maps in WinForm. Baidu Map currently supports Android development, iOS development, web development, service interface, specifically can be referred to the ' Baidu map open platform '.
"Dynamic load Baidu Map" involves the knowledge points:
The WebBrowser control, which is a control that comes with VS, enables users to navigate the Web page in the WinForm form. Used primarily with the Navigate function, which loads the document at the specified Uniform Resource Locator (URL) into a new browser window or System.Windows.Forms.WebBrowser control. For more information about this control, refer to the detailed instructions on MSDN.
Baidu map JavaScript API, call API in the Web page display Baidu map.
As follows:
The HTML code for calling Baidu maps is as follows:
1 <! DOCTYPE html> 2
The code for calling HTML on WinForm is as follows:
private void Baidumap01_load (object sender, EventArgs e) 2 {3 //htm file copy to program root 4 this.wbBaidu.Navigate ( AppDomain.CurrentDomain.BaseDirectory + "baidu01.htm", false); 5 }
"Load static diagram" involves knowledge points
Call Baidu's static diagram interface
PictureBox vs comes with a picture container that represents the Windows picture box control that is used to display an image.
Httpwebrequest,httpwebresponse Send/Receive HTTP requests in WinForm.
Thread is called in the background process in order not to let the interface die.
Converts the returned stream of bytes into an image object
As follows:
The code for calling the static diagram API in the WinForm program is as follows:
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; Ten using System.IO; one using System.Threading; namespace Demosharp {Public partial class Baidumap02:form, {18 Public BaiduMap02 () {InitializeComponent (); + private void Btnload_click (object sender, Event Args e) 23 {24//thread execution in threads t = new Thread (new ThreadStart (Initmap)); 26 T.start (); Initmap private void () {string url = "Http://api.map.baidu.com/staticimage/v2? Ak=akcode need to apply for &mcode=666666¢er=116.403874,39.914888&width=910&height=400&zoom=11 "; HttpWebRequest request = (HttpWebRequest) httpwebrequest.create (URL); Request. Method = "GET "; HttpWebResponse response = Request. GetResponse () as HttpWebResponse; while (true) (response). StatusCode = = Httpstatuscode.ok) PNS {$ Image img = Image.fromstream (response. GetResponseStream ()); This.pictureBox1.Image = img; a break; Thread.Sleep (1000); 43} 44} 45} 46}
Postscript:
Call Baidu Map related functions, you need to apply for the key (AK), personal development and learning to use mobile phone to register.
The above is the C # program embedded in Baidu map content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!