谷歌地图在vb.net

时间:2014-02-09 13:59:19

标签: vb.net google-maps

我想在vb.net应用程序中显示谷歌地图,谷歌地图的左侧面板除外。为此我创建了一个名为map()的函数,它使用我拥有的纬度和经度来查询google map api。以下是map()函数的代码,此代码将放在richtext框中,浏览器应该运行该富文本框中的代码。问题是html代码是在richtext框中编写的,但Web浏览器仍然没有显示地图,程序没有显示任何错误,但只是没有按预期工作。我不知道我解决这个问题的方法是否正确。还有其他办法。任何帮助将不胜感激。感谢。

Public Sub map()
    ' Dim addr As String
    Dim html As String
    html = "<!DOCTYPE html>" _
    & "<html>" _
    & "<head>" _
    & "<title>Simple Map</title>" _
    & "<meta name='viewport' content='initial-scale=1.0, user-scalable=no'>" _
    & "<meta charset='utf-8'>" _
    & "<style>" _
    & "html, body, #map-canvas {" _
    & "height: 100%;" _
    & "margin: 0px;" _
    & "padding: 0px" _
    & "}" _
    & "</style>" _
    & "<script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?      v=3.exp&sensor=false'></script>" _
    & "<script>" _
    & "var map;" _
    & "function initialize() {" _
    & "var mapOptions = {" _
    & "zoom: 8," _
    & "center: new google.maps.LatLng(" & TextBox2.Text & "," & TextBox3.Text & ")" _
    & "};" _
    & "map = new google.maps.Map(document.getElementById('map-canvas')," _
    & "mapOptions);" _
    & "}" _
    & "google.maps.event.addDomListener(window, 'load', initialize);" _
    & "</script>" _
    & "</head>" _
    & "<body>" _
    & "<div id='map-canvas'></div>" _
    & "</body>" _
    & "</html>" _

    RichTextBox1.Text = html
    WebBrowser1.Navigate(RichTextBox1.Text)

    End Sub

1 个答案:

答案 0 :(得分:1)

而不是“导航”,您应该使用“DocumentText”。

WebBrowser1.DocumentText=RichTextBox1.Text