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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.