Search code examples
socratasoda

Socrata distance_in_meters(...) returns errors even on 2.1 endpoint


When I make a query from the CMS Nursing Home Compare data and attempt to order using distance_in_meters(...) I get the following error:

Error: function distance_in_meters is not defined in SoQL.

The docs say distance_in_meters(...) works with the 2.1 endpoint (further information on endpoints are stuck in a redirect loop from the link at the top of that page at the time of this writing but you can get it from Google cache): https://dev.socrata.com/docs/functions/distance_in_meters.html

I have confirmed the data set is using the 2.1 endpoint.

To be sure it wasn't an issue with just the order clause, I also set it up in the select. Two variations:

  1. https://data.medicare.gov/resource/4pq5-n9py.json?$select=*,%20distance_in_meters(location,%20%27POINT%20(-78.9627624%2043.0171854)%27)%20AS%20range&$where=within_circle(location,43.0171854,-78.9627624,16093.44)
  2. https://data.medicare.gov/resource/4pq5-n9py.json?$where=within_circle(location,43.0171854,-78.9627624,16093.44)&$order=distance_in_meters(location,%20%27POINT%20(-78.9627624%2043.0171854)%27)

So, the question ultimately is does the 2.1 endpoint not support distance_in_meters(...) or am I missing something stupid obvious?


Solution

  • It looks like although you're looking at the API docs for the 2.1 endpoint, you're actually using the 2.0 one in your queries. You should use:

    https://data.medicare.gov/resource/b27b-2uc7.json
    

    ... instead of:

    https://data.medicare.gov/resource/4pq5-n9py.json
    

    I change the root endpoint to the 2.1 version, and the query looks like it returns the results you'd expect:

    https://data.medicare.gov/resource/b27b-2uc7.json?$where=within_circle(location,43.0171854,-78.9627624,16093.44)&$order=distance_in_meters(location,%20%27POINT%20(-78.9627624%2043.0171854)%27)