[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

distance between zip-code's and vb.net

Hi,
Is there a program where I give as parameters a startplace, and some extra zipcode's.
I want the distance between the zipcode's. e.g.
start:Amsterdam, places to visit Paris, Madrid, Bruxelles
I sent the zipcodes from the adress in this places to the program and
the return is Bruxelles 200 km, Paris 250 Madrid 1250.
As you maybe see it's sort in the right driving order
I want to sent the parameters from VB.NET.
Thnx.
0
dgb
Asked:
dgb
  • 4
  • 3
  • 2
2 Solutions
 
Wayne Taylor (webtubbs)AstronautCommented:
Google Maps -> http://maps.google.com/
0
 
dgbAuthor Commented:
Hi,
It's not what I'm looking for. I know this kind of programs. But i want to sent some zipcodes from my program to the program and get the distances as a result back. As mentioned in the question.
Thnx
0
 
Wayne Taylor (webtubbs)AstronautCommented:
Still use Google Maps. Send the web page the parameters, then parse the returned HTML to get the distance. The query will look something like this....

http://maps.google.com/maps?f=d&hl=en&geocode=&saddr=4810%2C+Australia&daddr=5330%2C+Australia&btnG=Get+Directions

Note that those are Australian Zip codes, so experiment and adjust as required.

Wayne
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
vb_jonasCommented:
Pretty cool! But a bit hard to parse the html. Another approach - which is not easier, but has more possibilities it to use google maps api. The drawback there is that you need to setup a webpage somewhere (afaik), and call it from your winforms app.
0
 
Wayne Taylor (webtubbs)AstronautCommented:
>>But a bit hard to parse the html

Not necessarily. Using Regular Expressions help a lot. I should know - it's what QuickEE uses ;-)
0
 
dgbAuthor Commented:
Hi Webtubbs,
I understand the way of getting the map with the distance in it, but how do i get only the distance.
Thnx
0
 
vb_jonasCommented:
Hi dgb, I think Webtubbs meant that you download the html page using something like this:

Public Function GetPageHTML( _
           ByVal URL As String) As String
  ' Retrieves the HTML from the specified URL
  Dim objWC As New System.Net.WebClient()
  Return New System.Text.UTF8Encoding().GetString( _
     objWC.DownloadData(URL))
End Function

Dim strFrom as String="London"
Dim strTo as String="Paris"
dim strUrl = "http://maps.google.com/maps?f=d&hl=en&geocode=&saddr=" & strFrom & "&daddr=" & strTo & "&btnG=Get+Directions"
Dim strFullPageHtml As String =GetPageHtml(strUrl)

Then use regular expressions, or something else to find the distance within strFullPageHtml.
0
 
vb_jonasCommented:
The piece of html containing the distance looks like this (London - Paris):

id=\"ddr_drivelink_0\"\x3eDrive\x3c/a\x3e:\x3c/td\x3e\x3ctd align=\"right\" nowrap class=\"timedist ul\"\x3e\x3cdiv class=\"noprint\"\x3e\x3cdiv\x3e289\x26#160;mi \x26#8211; about 5 hours 43 mins\x3c/div\x3e\x3c/div\x3e\x3cdiv class=\"pw\"\x3e289\x26#160;mi \x26#8211; about 5 hours 43 mins\x3c/div

Where 289 (look closely), is the distance (in miles). Now it's a bit of fun to find out a nice regular expression to extract that number. :)

0
 
vb_jonasCommented:
Here's one crude way to get & parse it (no, I could not keep my fingers away):
Public Function GetPageHTML( _
           ByVal URL As String) As String
  ' Retrieves the HTML from the specified URL
  Dim objWC As New System.Net.WebClient()
  Return New System.Text.UTF8Encoding().GetString( _
     objWC.DownloadData(URL))
End Function
    Function GetDistance(ByVal strFrom As String, ByVal strTo As String) As String
        Dim strUrl = "http://maps.google.com/maps?f=d&hl=en&geocode=&saddr=" & strFrom & "&daddr=" & strTo & "&btnG=Get+Directions"
        Dim strFullPageHtml As String = GetPageHTML(strUrl)
        Dim strSearchFor As String
        strSearchFor = "class=\""timedist ul\""\x3e\x3cdiv class=\""noprint\""\x3e\x3cdiv\x3e"
        Dim strSearchEnd As String = "\x26"
        Dim nPosition As Integer
        Dim nPositionEnd As Integer
        Dim strFound As String = ""
        nPosition = strFullPageHtml.IndexOf(strSearchFor)
        If nPosition <> 0 Then
            nPosition = nPosition + strSearchFor.Length
            nPositionEnd = strFullPageHtml.IndexOf(strSearchEnd, nPosition)
            strFound = strFullPageHtml.Substring(nPosition, nPositionEnd - nPosition)
        End If
        Return strFound
    End Function
----
 
Usage:
msgbox("Distance from London to Paris " & GetDistance("London","Paris"))

Open in new window

0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now