在VB.NET中打开生成的Web页面,包括Google Map

时间:2013-11-20 15:17:03

标签: html vb.net

我试图通过嵌入在我的VB.net应用程序中的Web浏览器打开Goog​​le Map API。我可以通过以下方式从本地桌面加载HTML文件来实现:

WebBrowser1.Navigate("file:///" & "C:\Users\username\Desktop\google-maps.html")

但现在我想在我的VB应用程序中直接添加HTML文件的内容:

sHTML = "<!DOCTYPE html><html><head>" _
& "<meta name='viewport' content='initial-scale=1.0, user-scalable=no'/>" _
& "<style type='text/css'>" _
& "html { height: 100% }" _
& "body { height: 100%; margin: 0; padding: 0 }" _
& "#map-canvas { height: 100% }" _
& "</style>" _
& "<script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?key=   <KEY>&sensor=false&libraries=weather'></script>" _
& "<script type='text/javascript'>" _
& "function initialize() {" _
& "var mapOptions = {" _
& "center: new google.maps.LatLng(46.073231,4.21875)," _
& "zoom: 2" _
& "};" _
& "var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);" _
& "};" _
& "google.maps.event.addDomListener(window, 'load', initialize);" _
& "</script></head><body>" _
& "<div id='map-canvas'/>" _
& "</body></html>"

WebBrowser1.Document.Write(sHTML)

但是当我运行此代码时,我必须遵循以下错误消息:&#34; google未定义&#34;。有什么想法吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

你必须这样做

WebBrowser1.Documenttext = shtml

如果您要从html file加载webbrowser,请使用

Webbrowser1.DocumentText = System.IO.File.ReadAllText("c:\myhtml.html")