WinForm調(diào)用百度地圖接口用法示例
本文實(shí)例講述了WinForm調(diào)用百度地圖接口用法。分享給大家供大家參考,具體如下:
1、首先用一個(gè)html文件調(diào)用百度地圖接口(主要注冊(cè)一個(gè)序列號(hào)):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>百度地圖的Hello World</title> <style type="text/css"> body, html, #allmap { width: 100%; height: 100%; overflow: hidden; margin: 0; } #l-map { height: 100%; width: 78%; float: left; border-right: 2px solid #bcbcbc; } #r-result { height: 100%; width: 20%; float: left; } </style> <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=6c497f51c06477544e5fa6e9bd68f7c3"></script> </head> <body> <div id="allmap"> </div> </body> </html> <script type="text/javascript"> //alert("Hello World"); var map = new BMap.Map("allmap"); // 創(chuàng)建Map實(shí)例 var point = new BMap.Point(121.504, 31.212); // 創(chuàng)建點(diǎn)坐標(biāo)(經(jīng)度,緯度) map.centerAndZoom(point, 11); // 初始化地圖,設(shè)置中心點(diǎn)坐標(biāo)和地圖大小級(jí)別 map.addOverlay(new BMap.Marker(point)); // 給該坐標(biāo)加一個(gè)紅點(diǎn)標(biāo)記 //var traffic = new BMap.TrafficLayer(); // 創(chuàng)建交通流量圖層實(shí)例 //map.addTileLayer(traffic); // 將圖層添加到地圖上 map.addControl(new BMap.NavigationControl()); // 添加平移縮放控件 map.addControl(new BMap.ScaleControl()); // 添加比例尺控件 map.addControl(new BMap.OverviewMapControl()); //添加縮略地圖控件 map.addControl(new BMap.MapTypeControl()); //添加地圖類型控件 map.setCurrentCity("上海"); //設(shè)置地圖顯示的城市 map.enableScrollWheelZoom(); //啟用滾輪放大縮小 function setLocation(x,y){//參數(shù):經(jīng)緯度 var point = new BMap.Point(x, y); map.centerAndZoom(point, 11); map.addOverlay(new BMap.Marker(point)); } </script>
2、建立一個(gè)Winform項(xiàng)目,用一個(gè)WebBrower控件查看html文件、調(diào)用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("https://www.baidu.com"); //這個(gè)文件于可執(zhí)行文件放在同一目錄 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的值,調(diào)用JavaScript腳本 webBrowser1.Document.InvokeScript("setLocation", new object[] { 121.504, 39.212 }); } } }
更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《WinForm控件用法總結(jié)》、《C#窗體操作技巧匯總》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#常見控件用法教程》、《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》及《C#程序設(shè)計(jì)之線程使用技巧總結(jié)》
希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。
- Winform實(shí)現(xiàn)調(diào)用asp.net數(shù)據(jù)接口實(shí)例
- C# Winform 調(diào)用系統(tǒng)接口操作 INI 配置文件的代碼
- C#實(shí)現(xiàn)百度ping推送功能的方法
- C#開發(fā)Android百度地圖手機(jī)應(yīng)用程序(多地圖展示)
- C#使用ImitateLogin模擬登錄百度
- 如何根據(jù)百度地圖計(jì)算出兩地之間的駕駛距離(兩種語言js和C#)
- C#實(shí)現(xiàn)百度網(wǎng)站收錄和排名查詢功能思路及實(shí)例
- C#實(shí)現(xiàn)解析百度天氣數(shù)據(jù),Rss解析百度新聞以及根據(jù)IP獲取所在城市的方法
- c#封裝百度web服務(wù)geocoding api 、百度坐標(biāo)轉(zhuǎn)換示例
- asp.net c# 調(diào)用百度pai實(shí)現(xiàn)在線翻譯,英文轉(zhuǎn)中文
相關(guān)文章
C#對(duì)list列表進(jìn)行隨機(jī)排序的方法
這篇文章主要介紹了C#對(duì)list列表進(jìn)行隨機(jī)排序的方法,涉及C#操作list列表的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04C#使用迭代器實(shí)現(xiàn)文字動(dòng)態(tài)效果的示例代碼
這篇文章主要為大家詳細(xì)介紹了C#如何通過使用迭代器實(shí)現(xiàn)文字動(dòng)態(tài)效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-02-02C#中WPF ListView綁定數(shù)據(jù)的實(shí)例詳解
這篇文章主要介紹了C#中WPF ListView綁定數(shù)據(jù)的實(shí)例詳解的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下2017-10-10