Find data from table using radius check in geomatry column

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

1 answer

  • answered 2022-01-25 14:30 Patrick Janser

    Have a look at the formula explained on Wikipedia:

    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.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum