Spatial Views and Php


Does this exist, yet? (querying a spatial view in php)

I’m going to be really bummed if it doesn’t, as I think I have the perfect test case. Is there a way to use spatial views or can someone show me a good workaround in PHP?

Here’s what I’ve done. I’ve made a spatial view - ListAllUsersSpatial, that returns users with latitude and longitude of their location.

function (doc, meta) { user ="user:xxx"); if(user==0 && doc.Latitude && doc.Longitude) { emit ( {type: "Point", coordinates:[doc.Latitude, doc.Longitude]},; } }

Then I use my bbox parameter to find users near me (example from my web console):


And the results are just what I want. However, now I want to actually use this query in my code. I’m using php for couchbase access.

But, code like this doesn’t work:

$BBox = LatLongBBox($Latitude, $Longitude, 6371, 40);
$BBoxString = $BBox[0].",".$BBox[1].",".$BBox[2].",".$BBox[3];

$options = array(
“limit” => 10,
“bbox” => $BBox

$result = $Couchbase->view(“user”, “ListAllUsersSpatial”, $options);
foreach ($result[“rows”] as $row)
echo “Key:”.$row[‘key’]." Value:".$row[‘value’]."\n";

Alas, I’m doing something wrong or spatial views are not supported :frowning:

Here is the error I see:

PHP Warning: Couchbase::view(): Unrecognized view option ‘bbox’ in /var/web/ on line 26
PHP Fatal error: Uncaught exception ‘CouchbaseServerException’ with message '[500, error, Error opening view ListAllUsersSpatial, from set default, design document _design/user: {not_found,


Anyone? Does this board get read? Is there a better place to pose these queries?


No you are at the good place, sorry for the delay…



It is currently not possible to access the spacial views from the PHP client.

You have to call the View REST API directly from PHP.

Note an Enhancement Request exists for this:



OK, Thanks for the response. The Views are what really sets couch apart from DynamoDB and the location query-able views (bounding box) are something I’d like to use. By ‘calling the REST API directly’ do you mean doing a web query and then parsing the output? (e.g. I’m not sure I’ll be able to do that with my app or I’m just nor sure how.