Q. Tayyab Majeed
Q. Tayyab Majeed

Reputation: 13

how can I use google map API for search near by places in laravel 5.4

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.

enter image description here

Upvotes: 0

Views: 1154

Answers (1)

Sheena Singla
Sheena Singla

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

Related Questions