Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1068327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:16:22+00:00 2026-05-16T20:16:22+00:00

I have just been developing a postcode distance calculator for my Dads company, where

  • 0

I have just been developing a postcode distance calculator for my Dads company, where all our customers are kept on file and every time a new potential customer makes an enquiry the system will check against all other customers’ postcodes. The problem is that it doesn’t yet do the distance calculation. Typing in a DT1 postcode with the distance set to 5 miles says that DT1, 2 and 3 are close by. DT2 says DT1 and 2, DT3 says DT1, 3 and 4. This doesn’t make any sense. Yet if I put in BH2 with a distance of 50 miles it will bring back Bournemouth, Dorchester, Portsmouth, Bath, Southampton and a couple of other towns. These are all correct – however I do not know what is going on with the DT postcodes. DT11 doesn’t bring back any (under 5 miles), nor does DT10 (except for themselves).

I first of all used the root of (x * x + y * y) – I believe this is called Pythagoras’ theorem.. not sure since it have been years since I used that term!!

I have also tried the following:

  $sinstuff = sin(deg2rad($latitude))*sin(deg2rad($latitude2));
  $cosstuff = cos(deg2rad($latitude))*cos(deg2rad($latitude2))*cos(deg2rad($longitude-$longitude2));
  $sumstuff = $sinstuff + $cosstuff;
  $acosstuff = rad2deg(acos($sumstuff));
  $distance = $acosstuff*60*1.1515; //dunno what the 60 and 1.1515 is all about - I got this formula off a website.

This is the formula which seems to be bringing up the weird results. I also notice that the exact distance between DT11 and DT11 is something like +/- 0.00000989{and lots of other numbers}. This also seems a bit odd since, surely, the distance between DT11 and itself is 0…

Has anyone ever done anything like this successfully before?

I do have a massive batch of files – about 158MB in total – containing every UK postcode in full, with its corresponding latitude and longitude. My aim is, rather than comparing the specified full postcode to every other full postcode, to work out which area codes are less than a certain distance away then compare the specified postcode to all the full postcodes which are within these areas. Is this efficient? Is there a more efficient way?

Any help with this would be greatly appreciated.

Regards,

Richard

PS I know there are some sites out there which tell you how to work out distances but I dont seem to be able to get any of them working correctly (as you can tell from above).

PPS I know I can use the Google API for this – but this is not an option since this is going to be an offline application running on a local installation of wamp server. It is for use at trade shows where we cannot guarantee an internet connection.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:16:23+00:00Added an answer on May 16, 2026 at 8:16 pm

    You’re use the haversine formula:

    $l1 ==> latitude1
    $o1 ==> longitude1
    $l2 ==> latitude2
    $o2 ==> longitude2

    (taken from http://www.go4expert.com/forums/showthread.php?t=339)

    function haversine ($l1, $o1, $l2, $o2)
    {
    $l1 = deg2rad ($l1);
    $sinl1 = sin ($l1);
    $l2 = deg2rad ($l2);
    $o1 = deg2rad ($o1);
    $o2 = deg2rad ($o2);
    return (7926 - 26 * $sinl1) * asin (min (1, 0.707106781186548 * sqrt ((1 - (sin ($l2) * $sinl1) - cos ($l1) * cos ($l2) * cos ($o2 - $o1)))));
    }

    That should give you the distance between both points.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been developing some computer vision tools with openCV, but every time that
I have been developing iPhone application and just started adding CoreData for persistence. However
So I have been developing against the iphone 3.0 beta's and have just gone
I have recently been developing a website for a company, with a full administration
I have been developing for iPhone from last 1-2 months and all the time
I have been developing a C# windows form application in XP. It all works
I have been developing on my Mac Mini. I have just paid to join
I have been developing our php based site on a development box that was
I have an iPad application that I have been developing on simulator just fine
I've been developing .net console applications using C# and have always just dictated what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.