Searching for a location near where I am....?

n1ql

#1

I am moving an existing database to Couchbase - and I am considering to refactor my data model. It may not be the fastest approach but on the other hand this may be the best opportunity to use some of the features in Couchbase.

I have an app that can be used to select a “place” and we have built quite a lot of meta data for “places” and I want to find the places closest to a specific location with a distance - and let the user select from a list what exact “place” he/she is at. I have this working in my current solution but think there may be better ways to do it in Couchbase. I have a data model that looks like this (just a snippet - in reality there are more than 10,000 places - and more location points):

[
    {
        "id": 8526,
        "name": "Gentofte Sø",
        "points": [
            {
                "lon": "12.5346378020",
                "lat": "55.7484672287"
            }
        ]
    },
    {
        "id": 8635,
        "name": "Selsø Sø",
        "points": [
            {
                "lon": "11.9985884817",
                "lat": "55.7481008967"
            },
            {
                "lon": "11.9976368281",
                "lat": "55.7528651857"
            },
            {
                "lon": "11.9972925154",
                "lat": "55.7483786810"
            },
            {
                "lon": "11.9969483001",
                "lat": "55.7438921715"
            }
        ]
    },
    {
        "id": 8796,
        "name": "Sneum Digesø",
        "points": [
            {
                "lon": "8.5997939012",
                "lat": "55.4370956962"
            },
            {
                "lon": "8.5987910689",
                "lat": "55.4383362789"
            }
        ]
    }
]

So my question is: How can I directly query this data and get a distance (metric) from the nearest points based on a lat/lon point that I provide?

Any special concerns re indexing to make it perform well?

Thanks in advance for any suggestions!


#2

Check this out by @keshav_m https://dzone.com/articles/speed-up-spatial-search-in-couchbase-n1ql
You can also use CURL function and do calculation on external datasorce Check out
https://blog.couchbase.com/google-artificial-intelligence-machine-learning-api-couchbase-n1ql/