2016-09-27 53 views
0

我想在我的C#WPF程序中將Google Maps集成到WebBrowserControl中。地圖載入控件並以正確的經度和緯度爲中心,但是我遇到了一些錯誤。首先,加載地圖並在幾秒鐘後出現一個錯誤框;添加Javascript函數來加載谷歌地圖C#WPF

enter image description here

其次,當我試圖在緯度和經度的位置添加一個標記,我甚至地圖加載之前得到一個錯誤都沒有。這是我的代碼到目前爲止;

mapWebBrowser.NavigateToString(@"<html xmlns=""http://www.w3.org/1999/xhtml"" xmlns:v=""urn:schemas-microsoft-com:vml""> 
           <head> 
           <meta http - equiv = ""X-UA-Compatible"" content = ""IE=edge""/> 
           <meta name = ""viewport"" content = ""initial-scale=1.0, user-scalable=no""/> 
           <script type = ""text/javascript"" 
           src = ""http://maps.google.com.mx/maps/api/js?sensor=true&language=""es"" ></script> 
           <script src = 'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js'> 
           </script><script type = ""text/javascript""> 
            function initialize() { 
             var latlng = new google.maps.LatLng(" + latitude + ", " + longitude + @"); 
             var myOptions = { 
              zoom: 16, 
              center: latlng, 
              mapTypeId: google.maps.MapTypeId.ROADMAP 
             }; 
             var map = new google.maps.Map(document.getElementById(""map_canvas""), myOptions); 
            } 
            function addMarker(Lat, Long) { 
             var latLng = new google.maps.LatLng(Lat, Long);    
             marker = new google.maps.Marker({ 
              position: latLng, 
              draggable: false, 
              animation: google.maps.Animation.DROP, 
             }); 
             markers.push(marker); 
             var markerCluster = new MarkerClusterer(map, markers) 
            } 
           </script> 
           </head> 
           <body onload = ""initialize()"" > 
            <div id=""map_canvas"" style=""width:100%; height:100%""></div> 
           </body> 
           </html>"); 

這是我試圖用來在地圖上添加標記的功能;

function addMarker(Lat, Long) { 
     var latLng = new google.maps.LatLng(Lat, Long);    
     marker = new google.maps.Marker({ 
        position: latLng, 
        draggable: false, 
        animation: google.maps.Animation.DROP, 
     }); 
     markers.push(marker); 
     var markerCluster = new MarkerClusterer(map, markers) 
} 

我在C#中調用;

mapWebBrowser.InvokeScript("addMarker", new object[] { latitude, longitude });

不幸的是,我說這兩種方法都導致問題之前。