Start a new topic

Android callJavascript() doesn't work properly


I'm working with Poi scripts in Android. I use a .setLocation() and it works fine but when i use .callJavascript() to calll the function loadfromjson, it runs and notices me "1 place loaded" but no marker displayed.

I really need help.

This is my codes :

private fun generatePoiInformation(location: Location): JSONObject {
// ensure these attributes are also used in JavaScript when extracting POI data
val ATTR_ID = "id"
val ATTR_NAME = "title"
val ATTR_DESCRIPTION = "description"
val ATTR_LATITUDE = "latitude"
val ATTR_LONGITUDE = "longitude"
val ATTR_ALTITUDE = "altitude"
// generates 20 POIs
val poiInformation = HashMap<String, Any>()
poiInformation.put(ATTR_ID, "1")
poiInformation.put(ATTR_NAME, "POI#")
poiInformation.put(ATTR_DESCRIPTION, "This is the description of POI#")
poiInformation.put(ATTR_LATITUDE, location.latitude)
poiInformation.put(ATTR_LONGITUDE, location.longitude)
// equals "AR.CONST.UNKNOWN_ALTITUDE" in JavaScript (compare AR.GeoLocation specification)
// Use "AR.CONST.UNKNOWN_ALTITUDE" to tell ARchitect that altitude of places should be on user level. Be aware to handle altitude properly in locationManager in case you use valid POI altitude value (e.g. pass altitude only if GPS accuracy is <7m).

Log.e ("Json", JSONObject(poiInformation).toString())
return JSONObject(poiInformation)
architectView.callJavascript("World.loadPoisFromJsonData(" + generatePoiInformation(mLocation) + ");")
/* Called to inject new POI data. */
loadPoisFromJsonData: function loadPoisFromJsonDataFn(poiData) {

The example Image Recognition already explained how images are loaded and displayed in the augmented
reality view. This sample loads an AR.ImageResource when the World variable was defined. It will be
reused for each marker that we will create afterwards.
World.markerDrawableIdle = new AR.ImageResource("assets/marker_idle.png", {
onError: World.onError


Since there are additional changes concerning the marker it makes sense to extract the code to a
separate Marker class (see marker.js). Parts of the code are moved from loadPoisFromJsonData to the
Marker-class: the creation of the AR.GeoLocation, the creation of the AR.ImageDrawable and the
creation of the AR.GeoObject. Then instantiate the Marker in the function loadPoisFromJsonData:
var marker = new Marker(poiData);

/* Updates status message as a user feedback that everything was loaded properly. */
World.updateStatusMessage('1 place loaded');

architectView.setLocation(mLocation.latitude, mLocation.longitude, mLocation.accuracy.toDouble())
1 Comment


I guess this is related to the user's location. Please have a look at the related SDK Samples and ensure that you generate the POIs after the first user location fires, and ensure to not load them on each location update by adding a variable like "latestPoiReloadLocation", or similar.
Also check the AR.context.cullingDistance. POIs that are too far away aren't rendered by default.

Some more hints around GEO AR experiences in the following:

* Visually indicate: fetching user location state and the fetching of POI data for the current position

* Indicate number of loaded POIs and consider use of the "indicator" drawable, so user can easily find out where to point the device at

* Use location.distanceToUser() to calculate the very latest distance and show it as part of the Marker info.

* Implement a "reload" mechanism, which allows the user to update the content on demand (e.g. after moving 100+ meters)

* Indicate when you see the need for a reload (delta to initial loading of POIs exceeds a predefined threshold, e.g. 100 meters)

* Consider the consumption POI data from an online source so you can maintain content without the need of an app-update. Either host a service which retrieves user's location as param or (depending on the # of POIs) store all POIs in a single JSON and filter them client side .

Hope this helps.

Best regards,
Andreas Fötschl

Login or Signup to post a comment