Looking to implement a “Find Nearest” process for a mobile web application that will auto select the closest match of an item in a dropdown list in a form based on the user’s current location.
Assuming we have the lat/long for each element of our list, and the persons location from the mobile device, what is the best method to locate the closest item? We will have approx 150-200 possible items and want the one closest to the user so we can set it as the default.
Is there a means to efficiently do this in JS or would it be better suited to server side?
You’ll need a loop to calculate distance and henceforth, the closest. Use the Haversine formula:
Better run your own benchmarks to find out if it would be better to do this server-side or client-side.