I am building a takeaway finder that will find takeaways within a set distance of a uk postal code. What will happen is the user puts his/her postcode in an input box and clicks submit, the site then searches for takeaways near the user. But the catch is that this search is based on the individual takeaways delivery distance. So if a takeaway has a delivery distance of say 8 miles and the persons postcode is within 8 miles of the takeaway it will show in the results.
So far I have uk postcode database with lang and lat coordinates and also the takeaway database table holds the takeaways own postcode and its delivery distance but not the long and lat values of the takeaways postcode.
I have following sql query but im not sure how to implement something like this using datamapper?
SELECT id , 6371 * ACos( Cos( RADIANS( latitude ) ) * Cos( RADIANS( 56.0062 ) ) * Cos( RADIANS( - 3.78189 ) - RADIANS( longitude ) ) + Sin( RADIANS( latitude ) ) * Sin( RADIANS( 56.0062 ) ) ) AS Distance
FROM postcodes
HAVING Distance <= '10'
ORDER BY Distance
Also would’nt mind a bit of advice on setting up the logic of the above takeaway finder
