This website uses cookies. Read about how we use cookies.

Calculate closest locations to a latitude and longitude

A working self-contained JavaScript example of how to search sitelist.json files for the closest location to a latitude and longitude.

Depending upon your browser, you may need to view the files from a web server.

The find-locations.js file uses a combined searching and sorting algorithm which is very fast compared to using separate steps. It can return the single closest site, ID and distance, or the n closest sites.

Unzip the file to a suitable location and load the location-search.html into a browser.

  • location-search.html
    • The main demonstration HTML page
  • find-locations.js
    • Support code for the HTML page
  • jquery-1.10.0.min.js
    • JavaScript framework
  • sitelist.json
    • A JSON representation of the sitelist.

In your final code you should load the sitelist from DataPoint and cache locally.

datapoint-location-search-example

Last updated: Jul 31, 2015 3:38 PM