Closed mwsasser closed 3 years ago
It sounds as if a simple loop over all records with a distance calculation against the reference point would solve your problem:
$referenceLocation = new Coordinate(52.5, 13.5);
$calculator = new Haversine();
$inside = [];
foreach ($locations as $location) {
if ($reference->distance($location, $calculator) <= 1000) {
$inside[] = $location;
}
}
$inside
will contain all records with a radius of 1,000 meters around $reference
.
Thank you @mjaschen.
Is it possible to find all the objects within a specified distance from a given location?
I've been using Haversine to do this with an old php 5 class. But I'm not sure how you'd do that with this library.
The examples show how to find distance between two specific locations. But I'd like to find all the locations within X miles or km, ordered by distance. Is that possible?
I already have a populated database table with all of the locations. They are postal codes with latitude and longitude columns.
Thanks for your help!