【问题标题】:Open generated Web page including Google Map in VB.NET在 VB.NET 中打开生成的网页,包括 Google 地图
【发布时间】:2013-11-20 15:17:03
【问题描述】:

我正在尝试通过嵌入在我的 VB.net 应用程序中的 Web 浏览器打开 Google 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)

但是当我运行此代码时,我必须看到以下错误消息:“google is undefined”。有什么想法吗?

谢谢。

【问题讨论】:

  • 试试我的回答应该会有帮助

标签: html vb.net


【解决方案1】:

你必须这样做

WebBrowser1.Documenttext = shtml

如果您想从 html file 加载 webbrowser,请像这样使用

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

【讨论】:

  • 哇!相当快的答案!它按预期工作。非常感谢;)。
  • @SkorPPio 欢迎您
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-15
  • 1970-01-01
  • 2012-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多