Windows下C#的GUI窗口程序中實(shí)現(xiàn)調(diào)用Google Map的實(shí)例
對谷歌地圖操作使用的是WebBrowser控件,通過對javascript的操作來實(shí)現(xiàn)對谷歌地圖的各種操作,所以首先要創(chuàng)建一個html文件,并賦給WebBrowser的URl:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>Google Maps</title> <link rel="stylesheet" type="text/css" /> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> var map; function initialize() {//初始化 var myLatlng = new google.maps.LatLng( 34.259442,108.947071); var myOptions = { zoom: 10, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } function zoomIn(){//放大函數(shù) var zoomLevel = map.getZoom(); if(zoomLevel < 21){ zoomLevel += 1; map.setZoom(zoomLevel); } } function zoomOut(){//縮小函數(shù) var zoomLevel = map.getZoom(); if(zoomLevel > 0){ zoomLevel -= 1; map.setZoom(zoomLevel); } } function markLocation(x,y){//標(biāo)記某個位置 var myLatlng = new google.maps.LatLng(x, y); map.setCenter(myLatlng); marker = new google.maps.Marker({ map: map, position: myLatlng, draggable:true, title:"緯度:"+x+" 經(jīng)度:"+y }); } </script> </head> <body onload="initialize()"> <div id="map_canvas"></div> </body> </html>
操作地圖的簡單函數(shù)都寫在javascript里
C#源文件如下
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace GoogleMapDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); string url = Application.StartupPath + "/map-simple.html"; webBrowser1.Url = new Uri(url);//指定url } private void toolStripButtonStart_Click(object sender, EventArgs e) { webBrowser1.Document.InvokeScript("initialize");//執(zhí)行jiavascript } private void toolStripButtonZoomIn_Click(object sender, EventArgs e) { webBrowser1.Document.InvokeScript("zoomIn"); } private void toolStripButtonZoomOut_Click(object sender, EventArgs e) { webBrowser1.Document.InvokeScript("zoomOut"); } private void toolStripButtonMark_Click(object sender, EventArgs e) { object[] obj = { toolStripTextBox1.Text, toolStripTextBox2.Text }; webBrowser1.Document.InvokeScript("markLocation", obj); } } }
PS:如果只是想單純地調(diào)用瀏覽器打開網(wǎng)頁,可以這樣:
private void lbllink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { //調(diào)用IE瀏覽器 System.Diagnostics.Process.Start("iexplore.exe", "http://www.google.cn"); //調(diào)用系統(tǒng)默認(rèn)的瀏覽器 System.Diagnostics.Process.Start( "http://www.google.cn"); } private void lbllink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { //調(diào)用IE瀏覽器 System.Diagnostics.Process.Start("iexplore.exe", "http://www.google.cn"); //調(diào)用系統(tǒng)默認(rèn)的瀏覽器 System.Diagnostics.Process.Start( "http://www.google.cn"); }
上一篇:Unity UGUI教程之實(shí)現(xiàn)滑頁效果
欄 目:C#教程
下一篇:詳解C#切換窗口
本文標(biāo)題:Windows下C#的GUI窗口程序中實(shí)現(xiàn)調(diào)用Google Map的實(shí)例
本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6589.html
您可能感興趣的文章
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并打開的方法
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#停止線程的方法
- 01-10WinForm實(shí)現(xiàn)仿視頻 器左下角滾動新聞效果的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#實(shí)現(xiàn)讀取注冊表監(jiān)控當(dāng)前操作系統(tǒng)已安裝軟件變化的方法
- 01-10C#實(shí)現(xiàn)多線程下載文件的方法


閱讀排行
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻 器左下角滾動新
- 01-10C#停止線程的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實(shí)現(xiàn)讀取注冊表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 04-02jquery與jsp,用jquery
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10delphi制作wav文件的方法