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 = meta.id.indexOf("user:xxx");
if(user==0 && doc.Latitude && doc.Longitude)
{
emit ( {type: "Point", coordinates:[doc.Latitude, doc.Longitude]}, meta.id);
}
}
Then I use my bbox parameter to find users near me (example from my web console):
…_spatial/ListAllUsersSpatial?bbox=25%2C-100%2C35%2C-90&connection_timeout=60000
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/matchclip.retiredastronaut.org/api/test_api_calls.php 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,
missing_named_view}]