Reputation: 3
I want to make an API using laraval which will have request of latitude and longitude and the response will provide json of location of user's nearest pharmacy
how can I do or simple example or tutorial similar ?
Upvotes: 0
Views: 131
Reputation: 144
If you already have the latitude and longitudes in your database you might as well query them yourself. This is from an older project (so may not work or be the best method) where I'm doing something similar:
$cities = City::select(DB::raw('*, ( 6367 * acos( cos( radians('.$latitude.') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('.$longitude.') ) + sin( radians('.$latitude.') ) * sin( radians( latitude ) ) ) ) AS distance'))
->having('distance', '<', 25)
->orderBy('distance')
->get();
Upvotes: 1