Wp Query : Order by distance lat,lon

This may not be possible using what WP_Query gives you out of the box, it wasn’t designed to do math across multiple parameters for sorting. You can filter via meta_query and provide bounds, and you can order by a single value, you can even order by multiple values, e.g. show all items by their lat, and use long if they have the same lat, but WP_Query can’t do the distance calculation.

To do this, you will need to construct a raw SQL to retrieve the post IDs, then pass those IDs into a WP_Query to fetch the posts your SQL query found.

Additionally, if it could, the SQL query would be very very slow. For this reason special table and column formats are generally used for long/lat if you want to be able to pass an arbitrary parameter for sorting. Most people solve this problem by doing the ordering in the browser, as this is usually accompanied by a map of sorts. Fundamentally what you want is very expensive/slow to produce and you’ve ran into a tradeoff of accuracy vs speed.