Question

I need help, or maybe at least an idea to make things work..

I am working on routing the travel of something through gps..
first off, I pre-loaded latlng points on my .accdb (3 points)
I want them to be connected through a route..
here :

For Each dtrow In gpsDtable.Rows
        gpsMarker = New GMapMarker_Custom(New PointLatLng(dtrow("Latitude"), dtrow("Longitude")), "vistaMarker")
        routes.Markers.Add(gpsMarker)
        'this code, adds all 3 points in the map as a marker..
        'yes it shows those 3. working good... then

        If routes.Markers.Count < 2 Then
           'this condition is, I think optional
           'I just used them because, routing needs to have 2 POINTS
           'so if there is no marker present, either side, exception
           'if there are 2, execute the code

        Else
           'this is the code to add the route between 2 points

            Dim rp As RoutingProvider = TryCast(mainMap.MapProvider, RoutingProvider)
            Dim route As MapRoute = rp.GetRouteBetweenPoints(gpsMarker.Position, gpsMarker.Position, False, False, CInt(mainMap.Zoom))
           'as you can see, I used gpsMarker as the first & last point
           'logically, I need it to be the same because
           'it will connect to itself since I use for each

            Dim r As New GMapRoute(route.Points, "")
            routes.Routes.Add(r)
        End If
    Next

In my theory..
tried to test this expecting to have : add marker, route, add second marker, route, add third marker and so on..
it came out to be, I think, it routes, but only routes to only one marker, the last one. so technically, you won't see a route. I start here, I stop here - something like that is happening.

I was thinking if you could help me have an idea, something like..

For each point in database  
add marker  
add second marker  
route  
add third  
route from second to third
and so on...

is there a way for VB to recognize the last marker? start from there and end on the new one..
or the marker that I want to be as the starting point and the end point. thanks SO

Was it helpful?

Solution

rp.GetRouteBetweenPoints(gpsMarker.Position, gpsMarker.Position, False, False, CInt(mainMap.Zoom))

As far as I can tell you set a route from gpsMarker to itself.

If you want to route a travel that goes through each point in gpsDtable.Rows then you can just connect each marker with a previous one. Something like this:

'DISCLAIMER: untested code
Dim rp As RoutingProvider = TryCast(mainMap.MapProvider, RoutingProvider)
Dim previousGpsMarker As GMapMarker_Custom
For Each dtrow In gpsDtable.Rows
    gpsMarker = New GMapMarker_Custom(New PointLatLng(dtrow("Latitude"), dtrow("Longitude")), "vistaMarker")
    routes.Markers.Add(gpsMarker)
    'If it's not a starting point
    If previousGpsMarker IsNot Nothing Then
        'Set a route from previous marker
        Dim route As MapRoute = rp.GetRouteBetweenPoints(previousGpsMarker.Position, gpsMarker .Position, False, False, CInt(mainMap.Zoom))            
        Dim r As New GMapRoute(route.Points, "")
        routes.Routes.Add(r)
    End If
    'Storing the previous marker
    previousGpsMarker = gpsMarker
Next
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top