Solved

# Distance between postcodes using google api

Posted on 2009-04-14
Medium Priority
784 Views
Anybody have any information on how to do what theaa.com do here http://www.theaa.com/route-planner/index.jsp or freemaptools do here - http://www.freemaptools.com/distance-between-uk-postcodes.htm ?

Thanks
0
Question by:suroma
• 3
• 3

LVL 8

Expert Comment

ID: 24221433
You appear to have two separate problems:

1) Getting the end point locations
2) displaying the distance and directions once you have the end points

For task 1 there is not enough information in your question on where your data is coming from or what kind of data you want to display.

Task 2 can be solved by looking at the tutorials at http://econym.googlepages.com/index.htm.  In particular part 4 will show how to display locations and get locations
0

LVL 8

Accepted Solution

rweil earned 900 total points
ID: 24221461
To get the straight line distance between the two points.
see http://www.experts-exchange.com/Databases/GIS_GPS/Q_20383758.html

or to get other comments, in the search box type -
distance between latitude longitudes
0

Author Comment

ID: 24743894
I am looking to get a distance between 2 postcodes. At the moment I am using a database of lat/long points for the main part e.g. TQ4 .... or TQ9 .... However this falls down when i try to get the distance between TQ9 6TT and TQ9 7TY which the current method returns 0.
0

LVL 8

Expert Comment

ID: 24744569
What are the latitude/longitude values?

What formula are you using to get the distance?
0

Author Comment

ID: 25558499
Here are the values for the TQ postcodes
TQ1      292000      64700
TQ10      270800      59900
TQ11      273600      66200
TQ12      285800      71200
TQ13      278400      78500
TQ14      293300      73400
TQ2      290500      65000
TQ3      288200      61600
TQ4      288500      59400
TQ5      291800      55800
TQ6      287000      50900
TQ7      273000      44100
TQ8      273700      39000
TQ9      280000      58800

An here is the stored proceedure
``````-- Get X & Y coords of home outcode
UPDATE @tableVariable SET
homeX = pc.x,
homeY = pc.y
FROM
@tableVariable t
INNER JOIN tblPostCodes pc ON SUBSTRING(t.postCodeHome,1,4) = pc.outcode

-- Get X & Y coords of destination outcode
UPDATE @tableVariable SET
destinationX = pc.x,
destinationY = pc.y
FROM
@tableVariable t
INNER JOIN tblPostCodes pc ON t.itemOutcode = pc.outcode

-- Calculate the distance & add to table
UPDATE @tableVariable SET
distance = (sqrt((power((destinationX - homeX),2)) + (power((destinationY - homeY),2)))) / 1609.344
``````
0

LVL 1

Assisted Solution

ajGurkha earned 600 total points
ID: 30159306
maybe there is type conversion error in your distance calculation. Possibly the power function treats inputs and outpus as a short integer. Try casting each portion of the calculation to a decimal.
0

Author Closing Comment

ID: 32900368
Not complete but no longer a priority to complete.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
###### Suggested Courses
Course of the Month9 days, 17 hours left to enroll