asimplecore
asimplecore

Reputation: 378

How to find nearest points using latitude and longitude from a DocumentDB collection?

I'm using Microsoft's DocumentDB to store locations of hundreds and thousands of geographic locations in the UK. A document from the database collection looks like the following.

  {
    "CommonName": "Cassell Road",
    "CommonNameLang": "en",
    "Street": "Downend Road",
    "StreetLang": "en",
    "Indicator": "SW-bound",
    "IndicatorLang": "en",
    "Bearing": "SW",
    "LocalityName": "Fishponds",
    "ParentLocalityName": "Bristol",
    "Easting": 364208,
    "Northing": 176288,
    "Longitude": -2.5168477762,
    "Latitude": 51.4844052488,
  },

What type of DocumentDB query could I use based on the user's latitude and longitude to find the nearest points from the collection?

Thanks

Upvotes: 2

Views: 394

Answers (1)

Aravind Krishna R.
Aravind Krishna R.

Reputation: 8003

You'll need a geospatial function like ST_NEAR or ST_DISTANCE. This is not currently available - you can check the status of the feature here.

Short-term, especially if have < 1000 documents, you might be able to use an existing geospatial library e.g., System.Spatial and perform processing client-side. Alternatively, you can use a JavaScript library like GeoJSON Utils within stored procedures to do this.

Upvotes: 4

Related Questions