Layar API

From LightRod

Revision as of 18:33, 28 February 2010 by Peter (Talk | contribs)
Jump to: navigation, search

Beta Software

See the description and download of this software here.


Contents

Getting started

Follow the instructions as per a normal search request. However, there are some additional function calls to operate a Layar server. The following is a complete, though simple, Layar server using LightRod:




require("cls.basic_geosearch.php");


$ly = new clsARLayarServer();
$ly_params = array('layar_name' => "PADZ",
			'debug' => true);		//Switch to false when taking server live
$ly->layar_request($ly_params);		
$params = array('latitude' => $ly->layar_latitude,	//Latitude in decimal degrees of center of search
	'longitude' => $ly->layar_longitude,		//Longitude in decimal degrees of center of search 
	'table_name' => "tbl_property",		        //Main table name that is being searched on 
	'id_field' => "int_property_id",	        //Unique reference to each point in the table
	'latitude_field' => "dec_latitude",	        //Field in table that has the latitude in decimal
	'longitude_field' => "dec_longitude",	        //Field in table that has the longitude in decimal
	'peano_field_header' => "int_peano",	        //First letters of fields in table that hold peano
                                                        //integers E.g. 'int_peano', which gets appended
		 				        //to create 'int_peano1, int_peano2, int_peano1iv,
		 				        // int_peano2iv'
	'radius' => $ly->layar_radius,
	'show_queries' => false	
);

$results_array = $ly->proximity_finder($params);	
$ly->layar_response($results_array);



Ensuring PHP has JSON

JSON comes with PHP 5.2, but earlier versions will need this installed.

E.g. on CentOS:



yum install gcc  (if not already installed)
yum install make
yum -y install php-pear && pecl install json
Then register the extension by creating a /etc/php.d/json.ini file with "extension=json.so"



layar_request() Parameters

These are representative of the Layar fields found at on their API, but remember these correspond with the database field names that hold these values, not the values themselves.

layar_name

layar_attribution

title

imageURL

actions_uri_1 (1-4)

actions_label_1 (1-4)

line_2 (2-4)

Note, unlike the Layar field name, this has an underscore '_' inbetween.

dimension

rel

angle

scale

baseURL

reduced

icon

size

alt

relative_alt

autoTriggerRange

autoTriggerOnly

morePages (New in version 1.09)

Set to true to allow for 'more' pages. False returns the first 10 results only. If true, you should also set


'provide_count' => true 

as a parameter in $params, before calling $ly->proximity_finder($params). And then you should call it in the following manner:


list($results_array, $count) = $ly->proximity_finder($params);	
$ly->layar_response($results_array, $count['show_next']);

debug

Set to true to display the results echoed to screen. False, passes back a pure JSON array.


More Complete Example

This example shows images in the real-world view. For ease of development in this example, the database field names correspond with the layar_request() parameters, but these are arbitrary. Note the use of the 'misc_fields' parameter for the additional fields, which is raw SQL. The values of the fields are hard-coded for the markers, so they will all look alike - but in actual practice they will come from your database.



require("cls.basic_geosearch.php");


$ly = new clsARLayarServer();
$ly_params = array('layar_name' => "padzdev",
			'actions_label_1' => "actions_label_1",
			'actions_uri_1' => "actions_uri_1",
			'line_2' => "line_2",
			'title' => "title",
			'imageURL' => "imageURL",
			'dimension' => "dimension",
			'rel' => "rel",
			'angle' => "angle",
			'scale' => "scale",
			'baseURL' => "baseURL",
			'full' => "full",
			'reduced' => "reduced",
			'icon' => "icon",
			'size' => "size",
			'debug' => true);		//Switch to false when taking server live
$ly->layar_request($ly_params);		
$params = array('latitude' => $ly->layar_latitude,	//Latitude in decimal degrees of center of search
		'longitude' => $ly->layar_longitude,	//Longitude in decimal degrees of center of search 
		'table_name' => "tbl_property",		//Main table name that is being searched on 
		'id_field' => "int_property_id",	//Unique reference to each point in the table
		'latitude_field' => "dec_latitude",	//Field in table that has the latitude in decimal
		'longitude_field' => "dec_longitude",	//Field in table that has the longitude in decimal
		'peano_field_header' => "int_peano",	//First letters of fields in table that hold peano
                                                        //integers E.g. 'int_peano', which gets appended
			 				//to create 'int_peano1, int_peano2, int_peano1iv,
			 				// int_peano2iv'
		'radius' => $ly->layar_radius,
                                                        //Replace these below with e.g. 'actions_label_1' if 
                                                        //you have the db field called that
		'misc_fields' => "'My Action' AS actions_label_1,    
				'http://www.yoururl.com' AS actions_uri_1,
				 'Hi there' AS line_2, 
				 'My Marker' AS title, 
				 'http://www.yoururl.com/assets/adverts/images/p-mayfair-house-95.jpg' AS imageURL,
				  2 AS dimension,
				  'true' AS rel,
				  0 AS angle,
				  10.0 AS scale,
				  'http://www.yoururl.com/assets/adverts/images/' AS baseURL,
				  'p-mayfair-house-95.jpg' AS full,
				  'p-mayfair-house-95.jpg' AS reduced,
				  'p-mayfair-house-95.jpg' AS icon,
				  20 AS size
				  ",
        	'show_queries' => false	
	);

$results_array = $ly->proximity_finder($params);	
$ly->layar_response($results_array);



Making your Layer visible to OAR browsers

Your layer can be tested immediately in an OAR (Open Augmented Reality) browser without any need to contact Layar. See the LightRod Open Augmented Reality Browser