Your Ad Here

Tuesday, September 11, 2012

Find location with in a distance by latitude and longitute



what i am tryng to do is i have entries in database which have a lat long store with them. I want to calculate distance between users lat/long and entries lat/long(in DB). After dat echo the ones with distance less dan 500 meter so far i am able to do this using "foreach"



SELECT *,3956 * 2 * ASIN(SQRT( POWER(SIN((lat - `latitude`) * pi()/180 / 2), 2) + COS(lat * pi()/180) * COS(`latitude` * pi()/180) *
            POWER(SIN((long - `longitude`) * pi()/180 / 2), 2) )) as
            distance FROM table GROUP BY `zipid` HAVING distance <= 500 ORDER by distance ASC


We can also use google api: https://developers.google.com/maps/articles/phpsqlsearch_v3