javascriptandroidaugmented-realitywikitude

What is the reason behind the use of Javascript in Wikitude SDK for Android?


I've been comparing several SDKs in order to add some location-based AR in one of my Android Apps. So far I've really liked the overall simplicity of Wikitude, however there are things like them asking you to put some of the logic of the AR part in javascript files that confuse me.

What are you supposed to do with the javascript, what role does it serves in the overall flow between an Android Activity and the AR?

Also, as a side question, what sense is there to make out of this line in the Android documentation of Wikitude:

architectView.callJavascript(newData('" + poiDataAsJson +")')

at http://developer.wikitude.com/documentation/android. I assume there is a typo or mistake somewhere as newData is not defined anywhere in the Android code.

Thank you!


Solution

  • In order to enable cross platform augmented reality experiences, web technologies were chosen. The application flow is usually that the ArchtiectView is initialised and displayed by the native application. An AR experience is loaded which consists of an html file that executes javascript functions to create the objects in AR.

    callJavascript method is used natively to communicate with the loaded AR exprience. It executes the passed javascript in the context of the loaded AR experience. Therefore it can be used to pass POI data as json to a function declared in the Javascript part.

    There is an error in the posted java code

    architectView.callJavascript(newData('" + poiDataAsJson +")')

    should include 2 more double quotes

    architectView.callJavascript("newData('" + poiDataAsJson +")'")

    This executes the function newData declared globally in javascript and passes 1 parameter, the json encoded poi data.

    Disclaimer: I work for Wikitude