0

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

default locale
  • 13,035
  • 13
  • 56
  • 62
AdorableVB
  • 1,383
  • 1
  • 13
  • 44

1 Answers1

1
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
default locale
  • 13,035
  • 13
  • 56
  • 62
  • that condition will not work. I used boolean, and the old one on my question. still, either `previous` does not have a value, or they are the same with `gpsmarker` .. working on it .. – AdorableVB Dec 27 '13 at 08:16
  • Why does this condition not work? Is `previousGpsMarker` always `Nothing`? What happens after the last assignment? P.S. `Count` condition from your question will skip the first marker. – default locale Dec 27 '13 at 08:24
  • that line is an error. maybe the API can't catch it. I used 2 so that it will have a start & end. because if its only a point, it would give out an exception. till now, I think its routing to itself. lol – AdorableVB Dec 27 '13 at 08:27
  • `Is operator does not accept operands of type Integer. Operands must be reference or nullable types.` – AdorableVB Dec 27 '13 at 08:35
  • @AdorableVB Please check out the updated code. It should be `IsNot` – default locale Dec 27 '13 at 08:41
  • what's the difference between the two? `is Not and isNot`? – AdorableVB Dec 27 '13 at 09:14
  • 1
    It was just a typo. `IsNot` is a separate operator, the opposite of `Not`. `Is Not` is a combination of two different operators, `Not` should be used on booleans and doesn't work properly here. – default locale Dec 27 '13 at 09:18