Reputation: 13
Basically, I am going to build a blood donating application in which I need a search bar to show all the nearby donors data which exist in my database in case of emergency.For this purpose, I want to use the GoogleMaps API nearby places.
How can I use this in my search bar?
I just want to build like this search bar here I enter my address and as a result, this gives me all nearby donor's list from my database.
Upvotes: 0
Views: 1154
Reputation: 816
You can use haversine formula
Below is the query using haversine formula in mysql
SELECT FLOOR( 3959 * ACOS( COS( RADIANS( '30.34' ) ) * COS( RADIANS( D.lat ) ) * COS( RADIANS( D.lng ) - RADIANS( '70.35' ) ) + SIN( RADIANS( '30.34' ) ) * SIN( RADIANS( D.lat ) ) ) ) distance
FROM donars
AS D
ORDER BY distance
LIMIT 0 , 30
Order by will sort rows in ascending order.
Upvotes: 1