MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Find distance between two addresses

This is a discussion on Find distance between two addresses within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; I have a chunk of code that I wrote to find the driving distance between two addresses. Excuse the name ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack (3) Thread Tools Display Modes
  3 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 06-26-2006
Junior Member
Yellow Belt
 
Join Date: Apr 2006
Posts: 20
Find distance between two addresses

I have a chunk of code that I wrote to find the driving distance between two addresses. Excuse the name "DoWork()" as it is just my naming for when I am trying things out.

Question 1 : In general am I going about it the correct way? Meaning adding waypoints to a route, calculating it, then looking at the distance.

Question 2 : I am using the data type of Object to eventually get to a Location. See this snippet.
Code:
Dim objLoc1 As MapPoint.Location
Dim objPin1OrLoc1 As Object
....
objPin1OrLoc1 = objMap.FindResults("1 Church St, Belfast ME 04915").Item(1)
....
objLoc1 = DirectCast(objPin1OrLoc1, MapPoint.Location)
Is this the preferred way to get a result from FindResult and feed it to a waypoint?

Here is the complete sub. It should be good to just copy and paste into a project if you already have a reference to Mappoint.

Code:
Private Sub DoWork1()
        Dim objMapPointApp As New MapPoint.Application
        Dim objMap As MapPoint.Map
        Dim objLoc1 As MapPoint.Location
        Dim objLoc2 As MapPoint.Location
        Dim objPin1OrLoc1 As Object
        Dim objPin2OrLoc2 As Object
        Dim objRoute As MapPoint.Route

        ' Prepare Map and Route with defaults
        objMap = objMapPointApp.ActiveMap
        objRoute = objMap.ActiveRoute

        ' Get the first result from potential addresses
        objPin1OrLoc1 = objMap.FindResults("1 Church St, Belfast ME 04915").Item(1)
        objPin2OrLoc2 = objMap.FindResults("100 W Main St, Troy, OH 45373").Item(1)

        ' If both addresses survived the process
        If (Not objPin1OrLoc1 Is Nothing) And (Not objPin2OrLoc2 Is Nothing) Then
            ' Cast objects to Mappoint.Location
            objLoc1 = DirectCast(objPin1OrLoc1, MapPoint.Location)
            objLoc2 = DirectCast(objPin2OrLoc2, MapPoint.Location)

            ' Add locations to waypoint
            With objRoute
                .Waypoints.Add(objLoc1)
                .Waypoints.Add(objLoc2)
                .Calculate()
            End With

            MessageBox.Show(objRoute.Distance.ToString)
        End If

        ' **********************
        ' Clean up afterwards
        ' **********************

        ' Avoid dialog box asking to save
        objMapPointApp.ActiveMap.Saved = True
        objMapPointApp.Quit()
        objMapPointApp = Nothing
    End Sub
[/code]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
addresses, distance, find


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/find-distance-between-two-addresses-5051.html

Posted By For Type Date
Web Link This thread Refback 09-12-2007 12:28 AM
Online Certificate - credits certificate, online instant This thread Refback 06-25-2007 08:33 PM
Loan Officer - lowest officer, officer kentucky This thread Refback 06-19-2007 07:55 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
How do I get the driving distance of two addresses? dawa MapPoint 2006/2009 Discussion 5 04-18-2008 02:23 AM
Why doesn't it find these addresses? pileggi MapPoint 2006/2009 Discussion 0 09-13-2005 03:01 AM
Find Addresses in Querycircle Anonymous MapPoint 2006/2009 Discussion 0 04-02-2004 03:45 AM
Find distance between two UK postal addresses by using VB AKPost MapPoint 2006/2009 Discussion 5 02-23-2004 11:18 AM
Calculate Distance Between 2 Street Addresses? Anonymous MapPoint 2006/2009 Discussion 4 10-08-2003 06:16 AM


All times are GMT -5. The time now is 10:56 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55