none
Offline Maps into VB.NET Apps RRS feed

  • Question

  • Hi guys,
    I'm not sure that this section is correct, but I do not know that it's correct.

    I'm developing a VB.NET App that resolves the vehicles routing problem. I have a lot of points (latitude, longitude) and i have to calculate the distance (time and chilometers) between them. Now, I use Google Maps and Bing as online services and save the results into a db.
    Is there a library or service that calculates this offline? (opensource/free or commercial is indifferent)?

    Thanks a lot.

    Sunday, July 16, 2017 4:43 PM

Answers

All replies

  • Hi guys,
    I'm not sure that this section is correct, but I do not know that it's correct.

    I'm developing a VB.NET App that resolves the vehicles routing problem. I have a lot of points (latitude, longitude) and i have to calculate the distance (time and chilometers) between them. Now, I use Google Maps and Bing as online services and save the results into a db.
    Is there a library or service that calculates this offline? (opensource/free or commercial is indifferent)?

    Thanks a lot.


    Do you mean "driving distance" (which can vary a lot depending on preference) or "as the crow flies" distance?

    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Sunday, July 16, 2017 4:56 PM
  • Gianluca,

    If you mean driving distance, you might want to start here:

    https://www.microsoft.com/maps/choose-your-bing-maps-API.aspx

    Bing Maps has an API that I've worked with some - search this forum for it and you'll probably come up with some examples.

    For "as the crow flies" distance - arclength really - this has been around for a while in various forms:

            Private Shared Function _
                GetDistance(ByVal Lat1 As Decimal, _
                            ByVal Lon1 As Decimal, _
                            ByVal Lat2 As Decimal, _
                            ByVal Lon2 As Decimal, _
                            ByVal Unit As String) As Decimal
    
                ' Although I've modified this some, I did *NOT* put this together
                ' originally and cannot take credit for it. Unfortunately I can't
                ' remember just where I got it now, but other than modifications,
                ' I didn't do it.
                '
                ' Although I haven't proven it to be correct, with each example
                ' that I've tried it on, the end result seems reasonable and thus
                ' I assume it to be correct.
                '
                ' Do note, however, this is the distance "as the crow flies".
    
                Dim x As Double
    
                ' do the nasty calcs
                x = (Math.Sin(DegToRads(Lat1)) * Math.Sin(DegToRads(Lat2)) + Math.Cos(DegToRads(Lat1)) * _
                    Math.Cos(DegToRads(Lat2)) * Math.Cos(Math.Abs((DegToRads(Lon2)) - (DegToRads(Lon1)))))
    
                If x > 1 OrElse x < -1 Then
                    Return 0
                Else
                    ' Get Acos(x)
                    x = Math.Atan((Math.Sqrt(1 - x ^ 2)) / x)
    
                    ' Get distance in kilometers
                    GetDistance = CDec(1.852 * 60.0 * ((x / Math.PI) * 180))
    
                    ' Convert units if necessary
                    Select Case Unit.ToUpper
                        Case "M"
                            GetDistance = CDec(GetDistance / 1.609344)
                        Case "N"
                            GetDistance = CDec(GetDistance / 1.852)
                    End Select
    
                    Return Math.Abs(GetDistance)
                End If
    
            End Function
    
            Private Shared Function DegToRads(ByVal Deg As Double) As Double
    
                DegToRads = CDbl(Deg * Math.PI / 180)
    
            End Function
    
    

    I have it set as "Shared" because I have that in a class library. I further enhanced it some with an interface:

      Friend Interface ILatLon
            ReadOnly Property Latitude As Decimal
            ReadOnly Property Latitude_String(Optional ByVal numberOfDecimalPlaces As Integer = 6) As String
    
            ReadOnly Property Longitude As Decimal
            ReadOnly Property Longitude_String(Optional ByVal numberOfDecimalPlaces As Integer = 6) As String
        End Interface

     - and -

            Public Shared Function _
                GetDistance(ByVal instance1 As ILatLon, _
                            ByVal instance2 As ILatLon) As Nullable(Of Decimal)
    
                Dim retVal As Nullable(Of Decimal) = Nothing
    
                Try
                    If instance1 Is Nothing Then
                        Throw New ArgumentNullException("Instance 1 of ILatLon", "Cannot be null." & vbCrLf)
    
                    ElseIf instance2 Is Nothing Then
                        Throw New ArgumentNullException("Instance 2 of ILatLon", "Cannot be null." & vbCrLf)
    
                    Else
                        retVal = GetDistance(instance1.Latitude, instance1.Longitude, instance2.Latitude, instance2.Longitude, "M")
                    End If
    
                Catch ex As Exception
                    Throw
                End Try
    
                Return retVal
    
            End Function

    I hope that's helpful. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Sunday, July 16, 2017 5:11 PM
  • Thanks to answered.

    Already, I used "as the crow flies". I need "driving distance". 

    I looked Bing API, but it's only in "online mode". I would like a offline service.
    For example, a software similar to Garmin, Tom Tom, etc that I send to it two geographical point and it returns me the distance from them without Internet connection.


    Tuesday, July 18, 2017 10:06 PM
  • Thanks to answered.

    Already, I used "as the crow flies". I need "driving distance". 

    I looked Bing API, but it's only in "online mode". I would like a offline service.
    For example, a software similar to Garmin, Tom Tom, etc that I send to it two geographical point and it returns me the distance from them without Internet connection.


    Without an internet connection I don't know of anything. It would be massive though (because it couldn't be dynamic).

    *****

    It would take a while but you could [potentially] do your own. Go through each permutation of "from here to there" and record the results in a DataTable or a collection of classes.

    Other than that I don't know what to suggest.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, July 18, 2017 10:18 PM
  • Already, I used "as the crow flies". I need "driving distance".

    There's an extensive list of options here:
    https://wiki.openstreetmap.org/wiki/Routing/offline_routers

    You will have to work through the list to determine which ones simply provide the service and which ones allow application access to the routing data.

    Tuesday, July 18, 2017 10:57 PM
  • Thank you.

    I try with Navit.

    Saturday, July 22, 2017 1:18 PM