couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Volker Mische <volker.mis...@gmail.com>
Subject Re: get item by longitude and latitude inside a square
Date Mon, 15 Mar 2010 17:24:38 GMT
Hi Stephane,

the problem is that CouchDB views sort by first part of the key, then by
the second. So the keys of your view might look like:

[1.45,2.45]
[20.96,19.75]
[38.58,3.18]
[45.09,60.30]
[45.09,72.20]
[47.92,23.78]

If you use startkey/endkey only once slice will be cut out. For
startkey=[35.0,1.0],endkey=[46.0,65.0] you'll only get
[38.58,3.18]
[45.09,60.30]
back (and not all the other ones where the second part of the key would
match.

As the others already proposed you need to use an geo-index solution
like geocouch, couchdb-lucene or a geohash.

Cheers,
  Volker

St├ęphane Mourey wrote:
> Hi all,
> 
> I have a database where cities (villes in french) are stored, with longitude
> and latitude values. I'm trying to get some of them, inside a square.
> Here is one request:
> 
> /sofitex/_design/all/_view/getVillesByLatAndLong?startkey=%5B6.84505190241%2C47.6459660001%5D&amp;endkey=%5B8.64494809759%2C49.4624339999%5D&amp;include_docs=true
> 
> Here is the view code:
> 
>    "getVillesByLatAndLong": {
>        "map": "function(doc) {if (doc.type=='ville')
> {emit([doc.lat,doc.long], doc);};}"
>    }
> The result is empty, but I know I have some cities that match. Could anyone
> tell what's wrong?
> 
> Best regards,
> 
> Stephane Mourey
> 


Mime
View raw message