0

Hi,

Let me explain with an example.

I have a postcode NW1 5LR and its LATITUDE:51.546069024064 LONGITUDE:-0.235949008191785 coming from user entry. I also have many other postcodes and their Latitide&Longitide values in database. What formula should I use to get only those postcodes which are in 1 mil away maximum?

Thanks

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by veledrom
0

Looks like I will use a SQL statement to calculate and return the places instead of doing same thing in PHP.

Another question is: The code below is for 1 MIL, What is I want in 1 KM?

SELECT ((ACOS(SIN($lat * PI() / 180) * SIN(lat * PI() / 180) + 
COS($lat * PI() / 180) * COS(lat * PI() / 180) * 
COS(($lon – lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515)
AS `distance` 
FROM `table_name` 
HAVING `distance` => '1' 
ORDER BY `distance` ASC

Apologised if not relevant to PHP. I know it is more like SQL thread but I though it would be a PHP thread.

Thanks

0

That SQL doesn't look right to me.

HAVING `distance` => '1' 

Should be

HAVING `distance` >= '1' 

?

1 mile = 1.609344 kilometres

Edited by diafol

0

I don't understand how this query knows that value 1 represents MILE or KM?

0

Well, it's beyond me. I'd have to sit down and think, wipe the nosebleed, sit down and think, recover from an stroke, sit down and think...

Seriously, there must be a script out there somewhere.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.