I’ve found it is a lot easier to use GeoCouch to do these kinds of queries. That said, you will have to create a bounding box (rather than a radius), which means you’ll need to use the Haversine formula client-side to figure out how big to make the box. If you want a radius of 5km, you’ll probably want to make the box a bit smaller since there’s a good amount of area within the box but outside the circle. I’ve got some old Ruby code I can dredge up if needed.
The GeoCouch couchdb1.3.x branch works on 1.5. That said, you're probably thinking about writing your views all wrong. You should be emitting key/value pairs (basically), and the key should be something to help look up your document. You might be able to emit something like this: [52, 13] [52.5, 13.3] [52.52, 13.39] [52.521, 13.396] (and so on) And then use the amount of precision lost as your level of filtering by radius. This obviously sucks, so give GeoCouch a try :). > Date: Wed, 19 Feb 2014 01:24:19 +0100 > Subject: Passing permanent changing arguments to a view? > From: [email protected] > To: [email protected] > > Hello! > > [Introduction] //skip if you want > My Name is Ben, I'm 34 years old from Germany. I'm developing Apps for iOS > and Ruby Backends. > [/Introduction] > > I'm new to couchDB, did some tutorials and really enjoyed working with > couchDB. > But now I'm stuck. > > I stored locations (doc) to my couchDB. > > e. g.: > { > name: "Location A", > latitude: 52.521156, > longitude: 13.396886 > } > > Because it's a mobile app, I only want to get docs within a radius of 5km. > But I really don't know how to query this. > > Is there a possibility to pass some arguments to a view? > Something like this: > > function(doc) { > if (doc.longitude> minLong > && doc.longitude < maxLong > && doc.latitude> minLat > && doc.latitude < maxLat) > emit(doc.name, null); > }; > > Or should every user create and update his own view? > > Thank you very much, > > Ben
