• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

Vb.net Mapping


I have an access database with 2 columns, a project number and the address; there's about 5000 records.

When working on a new project, many of the employees would like a way to determine if historically there are other projects that were done in proximity to their current project. In order to this I would have to have a way of searching through those 5000 records and somehow determining the closest projects based on the address they enter.

The only solution I found was to manually enter each address as a pin in Google Maps, they could then search the location of their project and then compare to the closest pins. Doing this with 5000 records is a terribly painful task, and the result will probably be difficult to handle for Google to display 5000 pins at once on screen.

I was wondering if there would be a simpler method using vb.net that does or doesn't necessarily involve a map?

All our projects are located in one city. Montreal, Canada

Thank you
1 Solution
See the reply by cletus here:


You can easiy translate it to VB.net

for example:
var dLat = (lat2-lat1).toRad();

 dim dlat as var= Math.PI ( lat2-lat1)/ 180

You can find latitude and longtitidue from GeoCoordinate  class.(if you have Framework 4+)

Otherwise google APi should provide you this.
FCapoAuthor Commented:
Thank you for your reply,

I really have no idea how to implement this, say I have a specific address, is there a way to obtain the Lat and Long from it in vb.net? If so is it possible to get a step by step on doing this?
Here is the code that will do what you want.  There is probably a more bulletproof way of handling the data back from Google.
You will need to add a reference to System.Web.Extensions.dll
Paste this code into a new form containing a single textbox.
Option Strict Off

Imports System.Text
Imports System.Net
Imports System.IO
Imports System.Web.Script.Serialization

    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim add As Address = CheckAddress("699 N Rush St, Chicago, IL")
        TextBox1.Text = String.Format("Lat = {0}  Lon = {1}",Add.Latitude, Add.Longitude)
    End Sub
    Public Class Address
        Public Property Street As String
        Public Property City As String
        Public Property State As String
        Public Property Zip As String
        Public Property Latitude As Decimal
        Public Property Longitude As Decimal
    End Class

        Public Function CheckAddress(ByRef Address As String) As Address
            Dim Result As New Address
                Dim Response As System.Net.HttpWebResponse = Nothing
                Dim sURL As String = String.Format("http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=false", Address.Replace(" "c, "+"c))
                Dim request As System.Net.HttpWebRequest = DirectCast(WebRequest.Create(sURL), HttpWebRequest)
                request.UseDefaultCredentials = True
                request.Timeout = 5000
                Dim proxy As IWebProxy = WebRequest.GetSystemWebProxy
                If proxy IsNot Nothing Then
                    proxy.Credentials = DirectCast(CredentialCache.DefaultCredentials, NetworkCredential)
                    request.Proxy = proxy
                    request.Proxy = Nothing
                End If
                Response = DirectCast(request.GetResponse(), HttpWebResponse)
                Dim ResultString As String = ResponseToString(Response)
                Dim serializer As New JavaScriptSerializer
                Dim AddressList As Dictionary(Of String, Object) = serializer.Deserialize(Of Dictionary(Of String, Object))(ResultString)
                Result.Street = String.Format("{0} {1}", AddressList("results")(0)("address_components")(0)("short_name"), AddressList("results")(0)("address_components")(1)("short_name"))
                Result.City = AddressList("results")(0)("address_components")(3)("short_name")
                Result.State = AddressList("results")(0)("address_components")(5)("short_name")
                Result.Zip = AddressList("results")(0)("address_components")(7)("short_name")
                Result.Latitude = AddressList("results")(0)("geometry")("location")("lat")
                Result.Longitude = AddressList("results")(0)("geometry")("location")("lng")
            Catch ex As Exception
            End Try
        Return Result
        End Function

    Private Shared Function ResponseToString(ByVal Response As HttpWebResponse) As String
        Dim ResultString As String = ""
            Using receiveStream As Stream = Response.GetResponseStream()
                Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
                ' Pipes the response stream to a higher level stream reader with the required encoding format.
                Using readStream As New StreamReader(receiveStream, encode)
                    Dim read(1024) As [Char]
                    ' Reads 1024 characters at a time.
                    Dim count As Integer = readStream.Read(read, 0, 1024)
                    While count > 0
                        Dim str As New [String](read, 0, count)
                        ResultString &= str
                        count = readStream.Read(read, 0, 1024)
                    End While
                    ' Releases the resources of the Stream.
                End Using
            End Using
        Catch ex As Exception
        End Try
        ' Releases the resources of the response.
        Return ResultString
    End Function

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now