0

I have around 200 lat,lng data. Need to find out which point among these is closest to a given lat,lng I am trying the brute force method, but it is inefficient.

Any pointers on alternatives?

I know programming language doesn't matter here but I am using php.

Bads123
  • 879
  • 2
  • 13
  • 26

1 Answers1

0

You must read the entire data to find the closest point, there's no optimization beyond that.

You'd have to iterate over the data and remember the smallest distance found so far and the coordinates for it's point.

To calculate the distance from current coordinates to your fixed point, you can use the distance formula

The procedure is simple - when you find a point with smaller distance, save its distance and coordinates to a variable, and keep going until you're done.

megapctr
  • 931
  • 1
  • 7
  • 19