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....

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.