EASILY ADD GOOGLE MAPS TO WINFORMS APPLICATIONS


Show a Map with Just a Few Lines of Code

It takes just a few lines of code to generate a Google Map. The code snipet below will generate all of the JavaScript needed to display the map on the left.

....
'Add a zatk_GoogleMap control
Dim zatk_GoogleMap As New zatk_GoogleMaps.zatk_GoogleMap
zatk_GoogleMap.Dock = DockStyle.Fill
Me.Controls.Add(zatk_GoogleMap)

'Add a single marker to the map
Dim clsM As zatk_GoogleMaps.Marker = zatk_GoogleMap.Markers.Add("Main")

'Geocode Wrigley Field
clsM.Address = "1060 W Addison St, Chicago, IL 60613"
clsM.InfoContent = "This is Wrigley Field. Home of your Chicago Cubs"

'Turn off auto zoom after map load
zatk_GoogleMap.ZoomToMarkersAfterLoad = False

'Set zoom level fairly close
zatk_GoogleMap.ZoomLevel = 17

zatk_GoogleMap.RenderMap() ....


Add Markers to Categories

Markers belonging to a Category can be given a custom appearance by using the BackColor, ForeColor and DotColor Properties of the Category Object.

As an alternative, the CustomImage Property can be used to set a System.Drawing.Image Object as the marker image.

The code snipet below shows how you might use the BackColor, ForeColor and DotColor Properties to give a custom appearance to all markers contained in a category.

....

Dim clsCat As zatk_GoogleMaps.Category = Nothing
Dim clsM As zatk_GoogleMaps.Marker = Nothing

'Add a category for Hilton hotels
clsCat = zatk_GoogleMap.Categories.Add("Hilton")
clsCat.BackColor = Color.Blue
clsCat.BorderColor = Color.White
clsCat.DotColor = Color.LightBlue

'Add some Hilton Hotels
clsM = clsCat.Markers.Add("Hilton 1")
clsM.Address = "720 South Michigan Avenue, Chicago, Illinois, 60605" ....


Use the System.Drawing.Image Object for Category or Marker Images

The System.Drawing.Image Object can by used for the CustomImage Property of the Category Object or the Marker Object.

The snipet of code below shows how the Category CustomImage Property might be used to display markers belonging to the Holiday Inn Category with the Holiday Inn logo image.


'Add a category for Holiday Inns
clsCat = zatk_GoogleMap.Categories.Add("Holiday Inn")

'Use the Holiday Inn logo for the marker
clsCat.CustomImage = My.Resources.HolidayInn

'Add some Holiday Inn Markers to the Holiday Inn Category
clsM = clsCat.Markers.Add("HI1")
clsM.Address = "640 N. Wabash Avenue , Chicago, IL 60611"

clsM = clsCat.Markers.Add("HI2")
clsM.Address = "350 West Mart Center Drive , Chicago, IL 60654"

clsM = clsCat.Markers.Add("HI3")
clsM.Address = "506 West Harrison Street , Chicago, IL 60607"


Use Category Object Methods to perform actions against groups of Markers

The Category Object contains a collection of Marker Objects.  The Category Object provides several Methods that allow you to perform actions against groups of markers withe a single call.

The snipet of code below shows how Tutorial 6 uses the SetBounce, SetOpacity and ZoomTo Methods of the Category Object.

....

Private Sub mnu_CatBounce_Click(sender As System.Object, _
            e As System.EventArgs)
    Dim cat As zatk_GoogleMaps.Category = sender.tag
    If sender.checked = True Then
        cat.SetBounce(False)
    Else
        cat.SetBounce(True)
    End If
End Sub

Private Sub mnu_CatOpacity_Click(sender As System.Object, _
            e As System.EventArgs)
    Dim cat As zatk_GoogleMaps.Category = sender.tag
    cat.SetOpacity(Val(sender.text))
End Sub

Private Sub mnu_CatZoomTo_Click(sender As System.Object, _
            e As System.EventArgs)
    Dim cat As zatk_GoogleMaps.Category = sender.tag
    cat.ZoomTo()
End Sub ....


Use Marker Object Methods to perform actions against individual Markers

The Marker Object provides several Methods that allow you to perform actions against individual markers.

The snipet of code below shows how Tutorial 7 uses the SetBounce, SetOpacity and ZoomTo Methods of the Marker Object.

....

Private Sub mnu_MarkerBounce_Click(sender As System.Object, _
            e As System.EventArgs)
    Dim m As zatk_GoogleMaps.Marker = sender.tag
    If sender.checked = True Then
        m.SetBounce(False)
    Else
        m.SetBounce(True)
    End If
End Sub

Private Sub mnu_CatOpacity_Click(sender As System.Object, _
           e As System.EventArgs)    
    Dim m As zatk_GoogleMaps.Marker = sender.tag
    m.SetOpacity(Val(sender.text))
End Sub

Private Sub mnu_CatZoomTo_Click(sender As System.Object, _
           e As System.EventArgs)
    Dim m As zatk_GoogleMaps.Marker = sender.tag
    m.ZoomTo()
End Sub ....


The GetMapImage Method returns the image of the current map

The GetMapImage Method returns a System.Drawing.Image Object containing the image of the current map.

The snipet of code below shows how Tutorial 15 demonstrates this Method.

....

Private Sub _btnMapImage_Click(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles _btnMapImage.Click
    Dim frmMapImage As New Form
    frmMapImage.BackgroundImage = zatk_GoogleMap.GetMapImage
    frmMapImage.BackgroundImageLayout = ImageLayout.Zoom
    frmMapImage.ShowDialog(Me)
End Sub

....