如何在表单中将标签绑定到Google Map?

时间:2012-07-29 02:53:45

标签: asp.net vb.net

Protected Sub FormView1_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBinding

    Dim streetAddres As String = Nothing
    Dim EventLabel As Label = FindControl("Event_locationLabel")
    Dim findMap As GMap = FindControl("GMap1")

    Dim GeoCode As GeoCode = Nothing
    ' Get user typed text from text box
    streetAddres = EventLabel.Text
    ' pass your city name in the geo code request it return geo code
    GeoCode = findMap.getGeoCodeRequest(streetAddres)
    ' Add the geocode in
    Dim gLatLng As New GLatLng(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng)
    ' Set center of map based on latitude and longitude coordinates
    findMap.setCenter(gLatLng, 16, GMapType.GTypes.Physical)
    Dim oMarker As New GMarker(gLatLng)
    ' Bind that marker data in google map
    findMap.addGMarker(oMarker)

End Sub

错误:

Object reference not set to an instance of an object.

已调试:已在行中停止:streetAddres = EventLabel.Text

1 个答案:

答案 0 :(得分:0)

问题是Event_locationLabel不是有效的控件ID。您需要检查页面以查看它应该被调用的内容。

如果由于某种原因阻止访问页面源,您可以打开Internet Explorer并按F12访问开发人员工具。这些对于识别(和调整)页面中的元素非常方便。