Jump to content

selecting results with range + Pythagoras theorem


Recommended Posts

i have a table for uk people that includes:

 

- postcode beginning (i.e. BB2)

- latitude (int)

- longitude (int)

- range (int, in miles, 1-20)

 

http://www.easypeasy.com/guides/article.php?article=64 - theres the article for the sql file i based my table on

 

now it says i can use Pythagoras theorem to calculate distances based on longitude and latitude.

 

so lets say i wanted to select all the people who are in range (based on the 1-20 they enter in the range field) of a postcode beginning i search for

 

for example, lets say i search for "BB2", i want a query that will select all of the people whose postcode beginning is "BB2", AND all the people within range of BB2 (going by the 1-20 mile range in their database field).

 

can some math whiz help me out?

Hi

 

Think the calculation you need is:-

 

WHERE ( 3959 * acos( cos( radians(#1#) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(#2#) ) + sin( radians(#1#) ) * sin( radians( lat ) ) ) ) < 20

 

where #1# is the latitude of your centre point and #2# is its longitude.

 

All the best

 

Keith

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.