Finding towns within a distance radius from a database

Discussion in 'Coding Help' started by oliflorence, Oct 29, 2010.

  1. oliflorence

    oliflorence New Member

    Hi everyone,

    I have been asked to write a script that will find towns within a radius of 10 miles (for instance) in a database.
    I have a database of towns with their corresponding latitude and longitude and I am fine working with the database, SQl etc but I have no idea how to work the coordinates.
    Does any one know how to calcuate distances using coordinates?
  2. MOH

    MOH New Member

    There's a few scripts here that might help
  3. php.allstar

    php.allstar New Member


    I wrote a method in a php class a few years back for calculating the distance between UK postcodes which worked by calculating the distance between grid reference points (northings and eastings), which I had stored in a database.

    With a bit of tweaking you could use this function to do what you need. However, you'll have to find someway of converting lat/long co-ordinates to grid references, you're on your own here so I advise you search google code as it may be done already.

    It's funny, this brings me back to my school days when we were doing trigonometry in Maths, and I said to my teacher: "Why would I want to know where a tree is going to fall when its cut, I've no interest in becoming a lumberjack!".

    So low and behold I got my first lesson in Latin maths, enter Pythagoras with his 'theorem' and the famous 'hypotenuse'!

    Anyway, sorry for going off in a tangent, it just instantly made me think of that day in school!


    function calcDistance($easting1,$northing1,$easting2,$northing2)

    // Calculate the northing and easting distance
    // Calculate the distance between the two points (Pythagoras' Theorem)
    $kms round($hypotenuse/1000,2);
    $miles $kms .62;

  4. darahogan

    darahogan New Member

    Hi oliflorence,

    I'm working on some regional analysis and need to create a database of irish towns and their latitude and longitude.

    Would you mind sharing the database you have?

    many thanks,
  5. oliflorence

    oliflorence New Member

    Hi There,
    I am afraid the project did not materialise for me so at the end i did not build the database, thus I might need similar shortly.

    Sorry i can't assist further.

Share This Page