0

I have an website where i am storing my company's location( longitude and lattitude ) in DB and i want to give an alert message( or any kind of response ) whenever an employee of my company enters within a given range( 500m ) of the company's location .

Can anybody please help me or me some idea how to do this .

it will be more helpfull if will be possible without any third party package .

Thanks .

kishan maharana
  • 623
  • 8
  • 10
  • did you checked this ? https://stackoverflow.com/questions/42821816/how-to-query-distances-between-two-coordinates-with-eloquent – Kamlesh Paul Dec 07 '20 at 12:03

1 Answers1

1

Try this to query in geolocation range

 DB::select(DB::raw("select * from (SELECT *, 6371
    * ACOS(COS(RADIANS(" . $lat . "))
    * COS(RADIANS(table_name.lat))
    * COS(RADIANS(table_name.lon)
    - RADIANS(" . $lon . "))
    + SIN(RADIANS(" . $lat . "))
    * SIN(RADIANS(table_name.lat))) AS distance
    FROM table WHERE status = 1 ) t where distance < 500"))

Above query there are added custom condition like status = 1 and range from 500. When you getting data then you send notification to the users

Jasim Juwel
  • 736
  • 8
  • 19