Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Postcode Distances

This is a discussion on Postcode Distances within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi, I tried using the above code with uk post codes entered by the user (as against reading from a ...

  1. #11
    ajanaman is offline Junior Member Yellow Belt
    Join Date
    Dec 2009
    Posts
    13

    Re: Postcode Distances

    Hi,

    I tried using the above code with uk post codes entered by the user (as against reading from a spreadsheet). i am using MP2004. What should I put in the line:

    Set objApp=CreateObj("Mappoint.Application.EU.16")

    At the moment i get on this line the error message:

    Activex component cant create object.

    Also what is the right format for the post code (SE19 1JX or SE191JX)?

    All i want to calculate is the driving distance and route between two postcode. If there is a simpler method, i will appreciate your help. Thanks.

    Ayo

  2. #12
    davidb is offline Senior Member Blue Belt
    Join Date
    Oct 2003
    Location
    London
    Posts
    290

    Re: Postcode Distances

    If I remember rightly for MP2004 you’ll need

    objApp = CreateObject("MapPoint.Application.EU.11")

    Make sure you’ve set up the reference to MP. In the vba window click on Tools, then References and then scroll down and tick the appropriate version of MP.

    I think MP is comfortable with either format for postcodes.

    If I take your final question literally then for calculating distance and route between 2 postcodes then you can use the package and forget about developing code. If in actual fact your requirement is more complicated and you need code then search this forum and you’ll find loads of code snippets.
    David
    UK mapping and map analysis services at www.broomanalysis.plus.com

  3. #13
    ajanaman is offline Junior Member Yellow Belt
    Join Date
    Dec 2009
    Posts
    13

    Re: Postcode Distances

    Thank David.

    i am developing in VB6, my code is below. When i run it,it just hangs and I have to ctrl+alt+del. All I want to do is calculate the driving distance between the postcodes entered in Text1 and Text2. Thanks for helping. Is there an activex component for this? Dont mind buying.

    The code:
    Code:
    Private Sub Command1_Click()
            MappointControl1.NewMap "c:\ccdmap\cleanmap.ptm"
            Dim objApp As New MapPoint.Application
            Dim objMap As MapPoint.Map
            Dim objRoute As MapPoint.Route
            Dim objLoc1 As MapPoint.Location
            Dim objLoc2 As MapPoint.Location
            Set objApp = CreateObject("MapPoint.Application.EU.11")
            
            objApp.Visible = False
            Set objMap = objApp.ActiveMap
            Set objRoute = objMap.ActiveRoute
                'Locate the 2 points
                Set objLoc1 = objMap.FindResults(Text1.Text)
                Set objLoc2 = objMap.FindResults(Text2.Text)
                'Calculate the route
                objRoute.Waypoints.Add objLoc1
                objRoute.Waypoints.Add objLoc2
                objRoute.Calculate
                
                'Drive Distance in kms
               Label3.Caption = "Driving Dist kms: " + objRoute.Distance
                'Drive Time in minutes
               Label4.Caption = "Driving Time mins: " + objRoute.DrivingTime
                'Straight Line Distance in kms (as a check)
                Label5.Caption = "Straight line dist kms: " + objMap.Distance(objLoc1, objLoc2)
                'objRoute.Clear
            
         objMap.Saved = True
         Set objApp = Nothing
         Set objMap = Nothing
         Set objLoc1 = Nothing
         Set objLoc2 = Nothing
         Set objRoute = Nothing
    End Sub
    ayo

  4. #14
    davidb is offline Senior Member Blue Belt
    Join Date
    Oct 2003
    Location
    London
    Posts
    290

    Re: Postcode Distances

    Sorry, my feeble programming experience only extends to vba and Python. I'd recommend searching this site for examples eg.

    Mappoint Control
    David
    UK mapping and map analysis services at www.broomanalysis.plus.com

  5. #15
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60

    Re: Postcode Distances

    I would set Visible to true for debugging - that can be very revealing as to what the problem might be!

    Eg. newer versions of MapPoint will display a nag screen in trial mode - this can't be dismissed when MapPoint is hidden.
    Also first-run MapPoint will usually give you a query about Wifi location.


    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  6. #16
    ajanaman is offline Junior Member Yellow Belt
    Join Date
    Dec 2009
    Posts
    13

    Re: Postcode Distances

    The problem was that I did not specify the correct active map, should have used:

    Set oMap=Mappointcontrol1.Activemap.

    That sorted it and was able to view the route.

    Thanks.

    ayo

  7. #17
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Re: Postcode Distances

    Here's some modified code that allows it to skip over postcodes it cannot find, and logs the rows to Excel VBA Immediate window

    Code:
    Option Explicit
    Dim objApp As New MapPoint.Application
     
    Sub Button1_Click()
     On Error GoTo LogError
    
     Dim omp As MapPoint.Map
     Dim ort As MapPoint.Route
     Dim ofr As MapPoint.FindResults
     Dim loc1, loc2 As MapPoint.Location
     Set objApp = CreateObject("MapPoint.Application.EU")
     objApp.Visible = True
     Set omp = objApp.NewMap
     Set ort = omp.ActiveRoute
     Worksheets("postcode.org").Cells(1, 3).Value = "Drive Distance"
     Worksheets("postcode.org").Cells(1, 4).Value = "Drive Time (mins)"
     Worksheets("postcode.org").Cells(1, 5).Value = "Straight Line Distance"
     
     Dim row As Integer
     row = 2
    
     Do While Worksheets("postcode.org").Cells(row, 2) <> ""
         Set ofr = omp.FindResults(Worksheets("postcode.org").Cells(row, 1))
         'If ofr.Count > 0 Then
           Set loc1 = ofr(1)
         'End If
         Set ofr = omp.FindResults(Worksheets("postcode.org").Cells(row, 2))
         'If ofr.Count > 0 Then
           Set loc2 = ofr(1)
         'End If
        
         ort.Waypoints.Add loc1
         ort.Waypoints.Add loc2
         ort.Calculate
        
         Worksheets("postcode.org").Cells(row, 3) = ort.Distance
         Worksheets("postcode.org").Cells(row, 4) = ort.DrivingTime
         Worksheets("postcode.org").Cells(row, 5) = omp.Distance(loc1, loc2)
        
         ort.Clear
         Set loc1 = Nothing
         Set loc2 = Nothing
        
         row = row + 1
     Loop
     
     omp.Saved = True
    Exit Sub
    
    LogError:
    Debug.Print "Postcode Lookup Failed Row: " & row & " " & Worksheets("postcode.org").Cells(row, 1) & " " & Worksheets("postcode.org").Cells(row, 2)
    Debug.Print Err.Number & " - " & Err.Description
    Resume Next
    
    End Sub
    ~ Order MapPoint MapPoint 2013 Here and Get Free Access to the MapForums Downloads ~
    ~~
    ~ Upgrade to Get Access to the MapForums Downloads ~

Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Distances 'as the crow flies'
    By TRK in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 01-20-2007, 03:25 AM
  2. Getting Distances
    By cmarquez in forum MapPoint Desktop Discussion
    Replies: 13
    Last Post: 10-17-2006, 09:34 AM
  3. Calculate distances
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 11-18-2004, 10:58 AM
  4. Batch Distances?!
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 01-21-2004, 12:40 PM
  5. hi, we are using mappoint to get distances for ou....
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 07-05-2002, 10:01 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127