0

I have table "vehicle_location" and "coordinates" column in table datatype is geomatry

and in my controller i am getting lat and long and radius in request so i want to find vehicle location data using radius

divakar
  • 61
  • 2
  • 10

1 Answers1

0

Have a look at the formula explained on Wikipedia: https://en.wikipedia.org/wiki/Great-circle_distance

You'll find someone asking about the same question here: Measuring the distance between two coordinates in PHP

Ideally, it would be good to be able to reduce the calculation of distances to only cars that are not to far from your location. So typically, I would start by an SQL query that only returns the vehicules which have latitude and longitude values in the nearby, according to the given radius.

Then, in a second step, you can calculate all the distances between these cars and your position, with the algorithm (which takes some calculation time) and sort them after.

The ideal thing to do is to try and do the calculation directly in SQL if possible, so that you can sort them and filter them with the radius. If it gets to complicated then do the calculation and sorting in PHP.

Patrick Janser
  • 3,318
  • 1
  • 16
  • 18