一个windows form,里面显示google地图,可以放大,缩小,拖动操作,最好有代码例子!对webbrowser控件的使用不是很熟练。

解决方案 »

  1.   

    已经知道了用Html的API可以<html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <!--导入Google Maps API库文件。注意将本代码中的API Key替换为前文申请到的API Key-->
        <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA1j86tnUDFv8OAtC8dZVtKRT8YXSkg32FmSueYimfV_yj5DJguRRW5eQHwEBk10jwkDxLKNltT_kuQA" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
        var map;
        //添加GControl()控件
        function load() {
          if (GBrowserIsCompatible()) {  
            map = new GMap2(document.getElementById("map"));
            
            //添加一个GMapTypeControl()控件
            map.addControl( new GMapTypeControl())
            //添加一个自定义位置GSmallMapControl()控件
            map.addControl( new GSmallMapControl(),
                    new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10)));
            
            //显示地图,并设置其中心,缩放值
            map.setCenter(new GLatLng(39.92, 116.46), 2);
          }
        }
        //]]>
        </script>
      </head>
      <!--加载时调用load()函数加载地图,注意加上onunload="GUnload()"防止内存泄露-->
      <body onload="load()" onunload="GUnload()">
        <!--以下id为map的DIV元素即为Google地图的容器-->
        <div id="map" style="width: 500px; height: 300px"></div>
      </body>
    </html>
    现在问题怎么把这个Hmtl赋给这个webbrowser ?应该有属性的吧
      

  2.   


    还得自己琢磨,太简单了,就几行代码
    首先添加一个html项<html xmlns="http://www.w3.org/1999/xhtml">
      <head></head>
      <body>
        <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://ditu.google.cn/maps?hl=zh-CN&amp;q=www.google&amp;ie=UTF8&amp;brcurrent=3,0x31508e64e5c642c1:0x951daa7c349f366f%3B5,0&amp;ll=35.140093,112.081146&amp;spn=9.707642,16.037571&amp;output=embed"></iframe><br />
      </body>
    </html>然后再读取内容附值给字符串,给documentText属性:public Form1()
            {
                InitializeComponent();            string str = null;            StreamReader sr = new StreamReader("../../HTMLPage2.htm", Encoding.Default);            webBrowser1.Navigate("about:blank");            webBrowser1.Document.OpenNew(true);            str = sr.ReadToEnd();            webBrowser1.DocumentText = str;        }
      

  3.   

    如果你的html里面有javascript代码,就得另外写了win.execScript("F1('日本')", "javascript");
      

  4.   

    刚学编程,我现在也遇到这个问题,有点小疑问
    StreamReader sr = new StreamReader("../../HTMLPage2.htm", Encoding.Default);
    最终每次运行这个form程序的话,它都会先去本地读这个"HTMLPage2.htm"文件,那这个程序在别人的电脑上怎么运行??难道我每次还要先把这个HTML文件拷过去??如果是这样的话,那为什么不直接webbrowser1.Navigate("../../HTMLPage2.htm")????????