scarhand Posted October 7, 2009 Share Posted October 7, 2009 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? Link to comment https://forums.phpfreaks.com/topic/176896-selecting-results-with-range-pythagoras-theorem/ Share on other sites More sharing options...
kickstart Posted October 7, 2009 Share Posted October 7, 2009 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 Link to comment https://forums.phpfreaks.com/topic/176896-selecting-results-with-range-pythagoras-theorem/#findComment-932709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.