Information about finding nearest neighbors is available at
https://geographiclib.sourceforge.io/C++/doc/nearest.html.

You will be redirected there. Click on the link to go there directly.