Simple code to draw a Route VB.NET

Topics: Windows Forms
Mar 9, 2012 at 10:14 AM

Is easy,

Dim RutaNueva As GMap.NET.WindowsForms.GMapOverlay 

Dim Ruta As MapRoute = GMapProviders.OpenStreetMap.GetRouteBetweenPoints(New PointLatLng(41.40963739, 2.15529274), (New PointLatLng(41.40748285, 2.15636874)), False, False, 5)

RutaNueva = New GMap.NET.WindowsForms.GMapOverlay(MiMapa, "RutaNueva")

MiMapa.Overlays.Add(RutaNueva)


 Dim p As GMap.NET.WindowsForms.GMapRoute

 p = New GMapRoute(Ruta.Points, "TestRoute")
 RutaNueva.Routes.Add(p) 

 MiMapa.ZoomAndCenterRoute(Ruta)

Bye.

Sep 9, 2014 at 2:34 PM
Edited Sep 9, 2014 at 3:02 PM
This is old sample code and no longer works....

Here is some new code for VB.Net - VS2012

For Each row As DataRow In dsDataStart.Tables(0).Rows
            dX1 = row.Item(0)
            dY1 = row.Item(1)
        Next
        dsDataStart = Nothing
        cProc.GetData(gsPCSQL_2, dsDataEnd)
        For Each row As DataRow In dsDataEnd.Tables(0).Rows
            dX2 = row.Item(0)
            dY2 = row.Item(1)
        Next
        dsDataEnd = Nothing

        'Place the Markers on the Map==========================

        Me.gmap_UK.Overlays.Clear()
        Me.gmap_UK.Overlays.Add(gmapDataOL)
        Me.gmap_UK.HoldInvalidation = True

        gmapDataOL.Markers.Add(New GMarkerGoogle(New PointLatLng(dY1, dX1), GMarkerGoogleType.green_big_go))
        ptStart = New PointLatLng(dY1, dX1)
        gmapDataOL.Markers.Add(New GMarkerGoogle(New PointLatLng(dY2, dX2), GMarkerGoogleType.red_big_stop))
        ptEnd = New PointLatLng(dY2, dX2)
        gmapDataOL.Markers(0).ToolTipText = sStartPostcode
        gmapDataOL.Markers(1).ToolTipText = sEndPostcode
        gmapDataOL.Markers(0).ToolTipMode = MarkerTooltipMode.Always
        gmapDataOL.Markers(1).ToolTipMode = MarkerTooltipMode.Always
        gmapDataOL.Markers(0).IsVisible = True
        gmapDataOL.Markers(1).IsVisible = True
        ' gmap_UK.ZoomAndCenterMarkers("MapData")
        Me.gmap_UK.Overlays.Add(gmapDataOL)
        gmapDataOL.IsVisibile = True

        'Now Place the Route on the Map
        myPen.Width = 3
        rMapRoute = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetRoute(ptStart, ptEnd, False, False, 15)
        g_Route = New GMapRoute(rMapRoute.Points, "RouteData")
        Me.txtInfo.Text = rMapRoute.Name ' Gives Miles + Time taken
        g_Route.Stroke = myPen
        gmapRouteOL.Routes.Add(g_Route)
        Me.gmap_UK.Overlays.Add(gmapRouteOL)
        gmapRouteOL.IsVisibile = True
        gmap_UK.ZoomAndCenterRoute(g_Route)
        gmap_UK.Refresh()