Create a simple vision layer
With getPOIs API v6.0, developers can create vision layers which can augment objects in the physical world. For more information on what Layar Vision is, please check out Layar Vision section. On layar website, there is an introduction video which shows how Layar Vision works.
If you have already followed the third tutorial about adding 2d /3d objects to a Geo-location layer, it is fairly easy to create a vision layer. Based on the sample code provided in the third tutorial, we will make the following changes:
- In the database - Add a new field "referenceImage" to the "POI" table.
- In the webservice
Add "referenceImage" field to the "POI" table
In the "POI" table, we will add a new field "referenceImage" and at the same time set the default value of "lat" and "lon" to NULL. Now the whole database looks like:

Change the logic of sql query to return vision POIs in getHotspots() function
Since vision POIs are not necessarily attached to a geo location, we do not need to return POIs based on the distance between the POI and the user. In this tutorial, we will change the sql query to return vision POIs based on the "poiType" in the "POI" table. We will return all POIs whose "poiType" is "vision".
Instead of returning "geolocation" in "anchor" object, return "referenceImage" parameter
For vision POIs, instead of returning lat, lon or alt parameters. we need to put "referenceImage" in "anchor" object.
Below is the getHotspots function which returns vision POIs. The changes mentioned above are in BOLD.
// Put received POIs into an associative array. The returned values are
// assigned to $reponse['hotspots'].
//
// Arguments:
// db ; The handler of the database.
// value , array ; An array which contains all the needed parameters
// retrieved from GetPOI request.
//
// Returns:
// array ; An array of received POIs.
//
function getHotspots( $db, $value ) {
// Define an empty $hotspots array.
$hotspots = array();
/* Create the SQL query to retrieve vision POIs. The first 50 returned POIs are selected.*/
// Use PDO::prepare() to prepare SQL statement. This statement is used due to
// security reasons and will help prevent general SQL injection attacks.
// $sql is returned as a PDO statement object.
$sql = $db->prepare( '
SELECT id,
imageURL,
title,
description,
footnote,
referenceImage,
iconID,
objectID,
transformID
FROM POI
WHERE POI.poiType = "vision"
LIMIT 0, 50 ' );
// Use PDO::execute() to execute the prepared statement $sql.
$sql->execute();
// Iterator for the response array.
$i = 0;
// Use fetchAll to return an array containing all of the remaining rows in
// the result set.
// Use PDO::FETCH_ASSOC to fetch $sql query results and return each row as an
// array indexed by column name.
$rawPois = $sql->fetchAll(PDO::FETCH_ASSOC);
/* Process the $pois result */
// if $rawPois array is not empty
if ($rawPois) {
// Put each POI information into $hotspots array.
foreach ( $rawPois as $rawPoi ) {
$poi = array();
$poi['id'] = $rawPoi['id'];
$poi['imageURL'] = $rawPoi['imageURL'];
// Get anchor object information
$poi['anchor']['referenceImage'] = $rawPoi['referenceImage'];
// get text object information
$poi['text']['title'] = $rawPoi['title'];
$poi['text']['description'] = $rawPoi['description'];
$poi['text']['footnote'] = $rawPoi['footnote'];
//User function getPOiActions() to return an array of actions associated
//with the current POI
$poi['actions'] = getPoiActions($db, $rawPoi);
// Get object object information if iconID is not null
if(count($rawPoi['iconID']) != 0)
$poi['icon'] = getIcon($db , $rawPoi['iconID']);
// Get object object information if objectID is not null
if(count($rawPoi['objectID']) != 0)
$poi['object'] = getObject($db, $rawPoi['objectID']);
// Get transform object information if transformID is not null
if(count($rawPoi['transformID']) != 0)
$poi['transform'] = getTransform($db, $rawPoi['transformID']);
// Put the poi into the $hotspots array.
$hotspots[$i] = $poi;
$i++;
}//foreach
}//if
return $hotspots;
}//getHotspots
In getPoiActions() function, return "autoTrigger" parameter instead of "autoTriggerRange"
for vision POIs, "autoTrigger" parameter should be used to determine whether a POI should be auto triggered. The changes in getPoiActions() function is in BOLD.
// Put fetched actions for each POI into an associative array.
//
// Arguments:
// db ; The database connection handler.
// poi ; The POI array.
//
// Returns:
// array ; An associative array of received actions for this POI.Otherwise,
// return an empty array.
//
function getPoiActions($db , $poi) {
// Define an empty $actionArray array.
$actionArray = array();
// A new table called 'POIAction' is created to store actions, each action
// has a field called 'poiID' which shows the POI id that this action belongs
// to.
// The SQL statement returns actions which have the same poiID as the id of
// the POI($poiID).
$sql_actions = $db->prepare('
SELECT label,
uri,
contentType,
activityType,
autoTrigger,
autoTriggerOnly,
params
FROM POIAction
WHERE poiID = :id ');
// Binds the named parameter marker ':id' to the specified parameter value
// '$poiID.
$sql_actions->bindParam(':id', $poi['id'], PDO::PARAM_STR);
// Use PDO::execute() to execute the prepared statement $sql_actions.
$sql_actions->execute();
// Iterator for the $actionArray array.
$count = 0;
// Fetch all the poi actions.
$actions = $sql_actions->fetchAll(PDO::FETCH_ASSOC);
/* Process the $actions result */
// if $actions array is not empty.
if ($actions) {
// Put each action information into $actionArray array.
foreach ($actions as $action) {
// Change 'activityType' to Integer.
$action['activityType'] = changetoInt($action['activityType']);
// If a POI is a vision enabled POI, we should use "autoTrigger". If a
// POI is a geo POI, we should use "autoTriggerRange".
$action['autoTrigger'] = changetoBool($action['autoTrigger']);
$action['autoTriggerOnly'] = changetoBool($action['autoTriggerOny']);
$action['params'] = changetoArray($action['params'] , ',');
// Assign each action to $actionArray array.
$actionArray[$count] = $action;
$count++;
}// foreach
}//if
return $actionArray;
}//getPoiActions
These are the only changes that we need to make based on the sample code of third tutorial. Please find the attached sample code here and start creating your own vision layers!