Layar Developer Documentation

Back to layar.com

PhoneGap Layar Plugin

The Layar plugin for Apache Cordova allows you to use the JavaScript code in your Cordova application as you use in your web application to build an augmented reality app.

Plugin requirements

The Layar plugin requires:

Limitations

Layer SDK callbacks are not supported in the plugin. Using the PhoneGap plugin you can launch a scan view or open a layar but cannot get javascript callbacks about what is going on. To implement callbacks please use the iOS and Android SDK natively.

Instalation guide

The Layar PhoneGap plugin requires Cordova CLI. To install the plugin in your app, execute the following code:

# Create initial Cordova app
$ cordova create myApp
$ cd myApp/

$ cordova platform add ios (For iOS)
$ cordova platform add android (For Android)

# Add the path you cloned the plugin to earlier
$ cordova -d plugin add /path/to/cloned/phonegap-layar-plugin

API Methods

Initialize

LayarPlugin.initialize(Layar Key, Layar Secret)

Initializes the Layar plugin with a consumer key and secret. 

Parameter (key) : The oauth consumer key 

Parameter (secret) :The consumer secret.

Please contact layer support to obtain a key and secret if you don not have one.

Premature return {Q.Promise} : you can use to implement success and failure callbacks

Open Scan View

LayarPlugin.openScanView()

Opens the AR camera view for scanning

Open URL

LayarPlugin.openURL(Layar URL)

Opens a layar view with a layar URL. This is mostly useful for opening geo layers with parameter Parameter url: The URL to open

 Example-> layar://yourlayarname?param=value

Open Layar

LayarPlugin.openLayar(Layername)

Opens a layar view with a layar name. Especially useful for opening geo layersparameter Parameter layername:The name of the layer to open. 

Example Application

Common Issues

 working with the SDK you might come across this common errors messages:

Nothing found (when scanning a Page)

Make sure that your Page is published as a Pro Campaign and not as a free one. Also make sure that the campaign belongs to the user you registered to receive the Key and secret.

An error occurred (we did not receive suitable response..) 

 Make sure that: