欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Windows下C#的GUI窗口程序中實(shí)現(xiàn)調(diào)用Google Map的實(shí)例

 更新時(shí)間:2016年04月09日 11:24:50   作者:hzy3774  
這篇文章主要介紹了Windows下C#的GUI窗口程序中實(shí)現(xiàn)調(diào)用Google Map的實(shí)例,如果只想調(diào)用瀏覽器打開網(wǎng)頁(yè)的話可以看文章最后的方法,需要的朋友可以參考下

對(duì)谷歌地圖操作使用的是WebBrowser控件,通過對(duì)javascript的操作來實(shí)現(xiàn)對(duì)谷歌地圖的各種操作,所以首先要?jiǎng)?chuàng)建一個(gè)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)記某個(gè)位置 
      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> 

 操作地圖的簡(jiǎn)單函數(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); 
    } 
  } 
} 

201649112352791.jpg (738×466)

PS:如果只是想單純地調(diào)用瀏覽器打開網(wǎng)頁(yè),可以這樣:

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");  
    } 

相關(guān)文章

最新評(píng)論