MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Find distance between two UK postal addresses by using VB

This is a discussion on Find distance between two UK postal addresses by using VB within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; To response the recent emails and questions that I’ve been asked of What and How Mappoint together with VB/VB.NET/VBA programming ...


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 Thread Tools Display Modes
  #1 (permalink)  
Old 10-12-2003
Junior Member
White Belt
 
Join Date: Oct 2003
Posts: 3
Find distance between two UK postal addresses by using VB

To response the recent emails and questions that I’ve been asked of What and How Mappoint together with VB/VB.NET/VBA programming languages can help improve your business by targeting your customers based on the UK geographic location, I have published the following code/tips and alone with a real world scenario that my program is trying to solve. Hope this would help!


A well-known restaurant chain has 70 odd branches across the UK. The restaurant Management promote its specific seasonal offers in a regular basis for each their branches only to the customer who lives within 2 miles radius distance. For central London however, 0.5 miles of distance is thought to be appropriate for their direct mailing campaign. Overlapping is strictly prohibited, as it would confuse customer if they receive two letters from two different branches.

More than 50,000 of their customer list was given in a format of MS Excel with full address and the UK postcode.

A solution was written by using VB.NET that calls an instance of Mappoint to measure the two address one at a time and pick up the qualified record from customer list and then output this record with the store code to a new file.


The most important measurement is handled by the following syntax;

Radius = locMaster.DistanceTo(oMap.FindResults(dr("PostCode "))(1))



Of course, you need to declare all your variables, including create instance of Mappoint at the beginning of your program;

Dim locMaster As MapPoint.Location


objApp = New MapPoint.Application
objApp.Units = MapPoint.GeoUnits.geoMiles


I used a loop that loops thru all our customer list by using a SqlDataReader dr().


While dr.Read

Radius = locMaster.DistanceTo(oMap.FindResults(dr("PostCode "))(1))

If Radius <= CType(txtRadius.Text, Double) Then
txtFileText.Text += strAddress(dr("CustomerID"), dr("Title"), dr("FirstName"), dr("LastName"), dr("Address1"), dr("PostTown"), dr("SubTown"), dr("SubLoca"), dr("County"), dr("PostCode")) & Trim(StoreCode.Text) & vbCrLf
iFounder = iFounder + 1
End If

If CInt(RecodRequired.Text) = i2Founder Then
Exit While
End If

End While
dr.Close()

I have also used a loop counter; iFounder to counts how many founds since sometime restaurant requires certain number of records from their list. For example, 200 for central London while 500 for Birmingham’s branch…etc
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 10-12-2003
Junior Member
White Belt
 
Join Date: Oct 2003
Posts: 3
Typoo, sorry

this should be;

If CInt(RecodRequired.Text) = iFounder Then
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 10-13-2003
Junior Member
White Belt
 
Join Date: Oct 2003
Posts: 8
so... whats wrong with this code

Sub Macro2()
'
' Macro2 Macro
' Macro recorded 06/10/2003 by Daniel Fountain
'
Dim objApp As MapPoint.Application
Dim objMap As MapPoint.Map
Dim objLoc1 As MapPoint.Location
Dim objLoc2 As MapPoint.Location
Dim objCenter As MapPoint.Location

'//open MapPoint and create a new map
Set objApp = New MapPoint.Application
objApp.Visible = True
objApp.UserControl = True
objApp.Activate
Set objMap = objApp.NewMap

objApp.Units = MapPoint.GeoUnits.geoMiles

objLoc1 = objMap.FindResults("IP1 5HN")(1)
objLoc1.DistanceTo (objMap.FindResults("IP5 3UT")(1))

'
End Sub

The error is on the "objLoc1 = objMap.FindResults("IP1 5HN")(1)" line and it says "object vairiable or with block object vairable not set"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 10-13-2003
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
syntex is 2002

Which version of Mappoint are you installed on your PC? If it's Mappoint 2000 or earlier, FindResult() has to have City/Town string variable and postcode to together for it to work. don't know why.

mine is MP 2002.

hope this help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 10-15-2003
Junior Member
White Belt
 
Join Date: Oct 2003
Posts: 8
its MP2002 europe - does the euro bit make a difference to this conversation?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 02-23-2004
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
close!!

objLoc1 = objMap.FindResults("IP1 5HN")(1)

should read

set objLoc1 = objMap.FindResults("IP1 5HN")(1)

;-]
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, postal


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
Find distance between two addresses WonderMonkey MapPoint 2006/2009 Discussion 0 06-26-2006 03:28 PM
Why doesn't it find these addresses? pileggi MapPoint 2006/2009 Discussion 0 09-13-2005 03:01 AM
Calculate Distance Between 2 Street Addresses? Anonymous MapPoint 2006/2009 Discussion 4 10-08-2003 06:16 AM
Postal Addresses To Coordinate Anonymous Wish List 2 05-06-2003 10:53 AM


All times are GMT -5. The time now is 09:52 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