0

Hi there,
How to get near by locations (around 5km) using latitude and longitude?

even i got sql query :
my table structure:
craete table ad_list(ad_list_id int(11) NOT NULL, lat decimal(10,6) NOT NULL, lng decimal(10,6) NOT NULL, PRIMARY KEY(ad_list_id));

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( $lat ) )
  * cos( radians( $lng ) - radians(-122) ) + sin( radians(37) ) 
  * sin( radians( $lat ) ) ) ) AS distance
FROM markers HAVING distance < 5 ORDER BY distance LIMIT 0 , 10;

Please give me a solution for this....

Edited by praba_web: mistook

3
Contributors
2
Replies
10
Views
1 Year
Discussion Span
Last Post by pritaeas
1

Do you have to use SQL? First, solve the problem mathematically using an arbitrary reference point (latitude and longitude). Compute what the L&L (latitude and longitude) would be for a distance of 5km from the reference point in any direction. Then, you will understand how to derive that from database entries. Note that you may want to compute this in an abstract manner, rather than just 5km east, west, north, or south of the reference location. That seems to be what you are trying to do, but SQL is NOT a good language for such abstractions unless you fully understand the permutations involved first.

This topic has been dead for over six months. 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.