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 :(

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,

1 Answer

« Back to question.


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: