Geospatial queries for Couchbase Lite? (Xamarin Forms .Net Standard App)

I’ve seen only a small mention of Couchbase Lite and geospatial queries local to the mobile device. Are geospatial queries possible against a Couchbase Lite database? (Note: not against a sync gateway or cb server, just against CB Lite 2.0+ database on the device only). If they are available, is there a demo xamarin app lying about that does the queries I could look over?

We haven’t implemented geospatial queries in 2.0. (We did have them in 1.x but only as an unofficial feature that was only supported on iOS.) It’s not a hard feature to implement, but we haven’t had enough developer demand.

(CC’ing @priya.rajagopal as input for her product roadmap.)

Thank you very much for the reply. I appreciate it. I would have imagined a lot of developer need for such a query. It seems counter-intuitive to end up with a fully synchronized set of data and subsequently not be able to geospatial query the local database - to save on rest api calls (etc…) if preferred ; which I think most folks would prefer. Thank you for considering it for your roadmap.

1 Like

I agree, it seems like a natural feature for mobile apps…

It’s possible to do bounding-box queries without specialized indexes; for example (pseudocode) loc.x BETWEEN $x0 AND $X1 AND loc.y BETWEEN $y0 AND $y1. With regular indexes on loc.x and loc.y (as opposed to R-trees) this isn’t very efficient, but it’s workable as long as your data set isn’t too large.

Hopefully related enough to stay as a reply, but do you have any good .Between examples that handle finding values between x and y for , lets call it a Latitude field which is double type.

I’m getting a Method Not Implemented couchbase lite thrown error when attempting the following…

  using (var query = QueryBuilder.Select(SelectResult.All())
 .From(DataSource.Database(_database))                
 .Where(Expression.Property("_type").EqualTo(Expression.String(typeof(T).Name))
 .And(Expression.Property("tag").EqualTo(Expression.String(clientId)))
.And(Expression.Property("Latitude")).Between(Expression.Double(latitude1),Expression.Double(latitude2))
    ))

is why I ask. I’ve looked around for reasonable numeric based .Between examples using querybuilder, not to much avail. Is there anything outright WRONG with that .Between expression? I get a ‘Method Not Implemented’ error from couchbase lite 2.1

There is something subtly, but outright wrong with it. The error message is laughably vague, so sorry about that (but I’m not entirely sure it would have helped anyway) but you have an extra closing parenthesis after Expression.Property("Latitude")

EDIT To clarify, it was a ‘method not supported’ error because that was a query that was attempting to check if the result of the previous “AND” was between the two values (something that we can not quite do yet)

Yep that fixed it! Thank you!