First Layar Tutorial

We introduced layar a few days ago (Introducing Layar), so now it's time to do something with it.


Topics covered:

  • Creating a new layar account
  • Creating and editing a new layer
  • Specifiing API endpoint
  • Prepare the database
  • Build a web service
  • Testing & Publishing the layer



First, go to https://www.layar.com/accounts/login/?next=/publishing/ and register for a free account.
After you have logged in, you could press 'Create a new Layer', but don't! First we have to create a database and build a webservice.
Prepare the database
Sign in to your MySQL database, create and select a new database, name it to whatever, and run the following

  1. CREATE TABLE IF NOT EXISTS `POI_Table` (
  2.   `id` varchar(255) NOT NULL,
  3.   `attribution` varchar(150) default NULL,
  4.   `title` varchar(150) NOT NULL,
  5.   `lat` decimal(20,10) NOT NULL,
  6.   `lon` decimal(20,10) NOT NULL,
  7.   `imageURL` varchar(255) default NULL,
  8.   `line4` varchar(150) default NULL,
  9.   `line3` varchar(150) default NULL,
  10.   `line2` varchar(150) default NULL,
  11.   `type` int(11) default '0',
  12.   `dimension` int(1) default '1',
  13.   `alt` int(10) default NULL,
  14.   `relativeAlt` int(10) default NULL,
  15.   `distance` decimal(20,10) NOT NULL,
  16.   `inFocus` tinyint(1) default '0',
  17.   `doNotIndex` tinyint(1) default '0',
  18.   `showSmallBiw` tinyint(1) default '1',
  19.   `showBiwOnClick` tinyint(1) default '1',
  20.   PRIMARY KEY  (`id`)
  21. ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

Fill it with sample data:
  1. INSERT INTO `POI_Table`
  2.                (`id`, `attribution`, `title`, `lat`, `lon`, `imageURL`, `line4`, `line3`, `line2`, `type`, `dimension`, `alt`, `relativeAlt`, `distance`, `inFocus`, `doNotIndex`,                `showSmallBiw`, `showBiwOnClick`)
  3. VALUES
  4. ('1', 'The Location of the Layar Office', 'The Layar Office', '52.3741180000', '4.9342500000', 'http://custom.layar.nl/Layar_banner_icon.png', '1019DW Amsterdam', 'distance:%distance%', 'Rietlandpark 301', 1, 1, NULL, NULL, '0.0000000000', 0, 0, 1, 1);

Change the properties if you want.. You can check your latitude and longitude coordinates by visiting Google Maps


Build up a web service
Modify and place the attached file: api.txt in a webserver, rename it to api.php.
Be sure to change the database access values in the php file.
Scroll down to /* * * Main entry point ** */, and change DB settings.



Creating and testing the layer
Now create a layer and specify the access url to your api endpoint. i.e.:http://example.com/api.php
For layer type, use 2D.
To publish the layer, you can press the "publish" button next to each layer under "layers" tab on the publishing site

Go now to Android Market, and download Layar if you haven't done it already.
Log in with your account, and search for your Layer to see it in action.

If you're doing it right, you should see something like this:

This is the end for the first tutorial, but stay tuned, we are coming with more.