我有一个像Map.Html的HTML文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title></title> <script type="text/javascript" src="http://maps.google.com.mx/maps/api/js?sensor=true"></script> <script type="text/javascript"> var geocoder; var map; function initialize() { geocoder = new google.maps.Geocoder(); var myOptions = { zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP } var address = "Ahmedabad, India" //change the address in order to search the google maps geocoder.geocode({ 'address': address }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); var infoWindow = new google.maps.InfoWindow({ content: 'Hello' }); google.maps.event.addListener(marker, "click", function (e) { infoWindow.open(map, marker); }); } else { alert("Geocode was not successful for the following reason: " + status); } }); map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } </script> </head> <body onload="initialize()"> <div id="map_canvas" style="width:100%; height:100%"></div> </body> </html>
然后我加载这个HTML文件在webbrowser控制DocumentText使用下面的代码:
using (StreamReader reader = new StreamReader(System.Windows.Forms.Application.StartupPath + "\\Map.html")) { _mapHTML = reader.ReadToEnd(); } webBrowser1.DocumentText = _mapHTML;
但地图加载不正确。 放大/缩小,地图/卫星选项,标记正在显示,但在地图上显示一个白色图层。
解决 – 至少对我来说。
由于某种原因,Web浏览器控件默认为错误的版本(实验?)。 我改变了我的初始化脚本来指定当前的3.3版本,一切都恢复正常。
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.3"></script>