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 person has this problem


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

I do not understand why World.loadPoisFromJsonData after architectView.callJavascript call keeps complaining my latitude is not within -90, 90. I have checked it is confirmed within -90, 90. 

2021-06-29 16:13:04.167 14080-14080/com.wikitude.sdksamples D/SimpleGeoArActivity: location.hasAltitude() 1

2021-06-29 16:13:04.168 14080-14080/com.wikitude.sdksamples D/SimpleGeoArActivity: JS Long = 103.XXXXXX lat = 1.XXXXXX ALT = 37.0

2021-06-29 16:13:04.185 14080-14080/com.wikitude.sdksamples D/Msg_box: onStop

2021-06-29 16:13:04.185 14080-14080/com.wikitude.sdksamples D/Msg_box: onDestroy

2021-06-29 16:13:04.209 14080-14080/com.wikitude.sdksamples I/Toast: Show toast from OpPackageName:com.wikitude.sdksamples, PackageName:com.wikitude.sdksamples

2021-06-29 16:13:04.238 14080-14080/com.wikitude.sdksamples I/chromium: [INFO:CONSOLE(1)] "Uncaught ARchitect Error: latitude is not in the valid range [-90, 90]<br /> at Object.create (<br /> at c.validateLatitude (<br /> at c.init (<br /> at c.<computed> [as init] (<br /> at new c (<br /> at Object.loadPoisFromJsonDataFn [as loadPoisFromJsonData] (file:///android_asset/samples/08_PointOfInterest_1_PoiAtLocation/js/poiatlocation.js:50:30)<br />", source: (1)

saveCoordinates: function saveCoordinatesFn(poiData)


        var singlePoi = {


            "longitude": parseFloat(poiData.longitude),

            "latitude": parseFloat(poiData.latitude),

            "altitude": parseFloat(poiData.altitude),

            "description": poiData.description,





I am following this example and

I do not understand why the data is NaN following the examples mentioned above. JSON data is healthy.

Using 9.8.0 SDK

2021-06-30 11:29:09.942 3873-3873/com.wikitude.sdksamples D/SimpleGeoArActivity: JS string info = [{"altitude":"37.0","latitude":"1.XXXXXX","name":"LOCATION#1","description":"Description for LOCATION#1","id":"1","longitude":"103.XXXXXX"}]

alert('ALT = ' + singlePoi.altitude + ' LAT = ' + singlePoi.latitude + ' LONG = ' + singlePoi.longitude);


final JSONArray jsonArray = generatePoiInformation(loc);

architectView.callJavascript("World.saveCoordinates(" + jsonArray.toString() + ")");

Log.d(TAG, "JS string info = " + jsonArray.toString());


the document did not mention much to get it working, and there is no such example ( to follow.

Hi Jay,

Could you please first answer the following questions:

  • Which version of the SDK are you using?
  • What device does this happen with (model details and OS version)?
  • Is this happening with the sample app or in your own app? If it happens with your own app, does the sample app work on your device?



Which version of the SDK are you using?

Jai>> 9.8.0, i mentioned.

What device does this happen with (model details and OS version)?

Jai>> Android 11, Xiaomi Mi 11.

Is this happening with the sample app or in your own app? If it happens with your own app, does the sample app work on your device?

Jai>> in my own app, the sample app got no such example.

I like to know can I change the following code?

architectView.callJavascript("World.loadPoisFromJsonData(" + jsonArray.toString() + ")");


architectView.callJavascript("World.Jaisenddata(" + jsonArray.toString() + ")");


Ok, i found the problem, I still need to loop through the JSondata even though there is only one group of location data. Thanks
Login or Signup to post a comment