Start a new topic
Solved

Android callJavascript() doesn't work properly

 Hello,


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)
val UNKNOWN_ALTITUDE = 100.0f
// 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).
poiInformation.put(ATTR_ALTITUDE, UNKNOWN_ALTITUDE)

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
});

AR.logger.debug(poiData.latitude);

/*
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

Hello,


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 (https://www.wikitude.com/libs/architect.js:1:6989)<br /> at c.validateLatitude (https://www.wikitude.com/libs/architect.js:1:80516)<br /> at c.init (https://www.wikitude.com/libs/architect.js:1:78480)<br /> at c.<computed> [as init] (https://www.wikitude.com/libs/architect.js:1:4803)<br /> at new c (https://www.wikitude.com/libs/architect.js:1:4666)<br /> at Object.loadPoisFromJsonDataFn [as loadPoisFromJsonData] (file:///android_asset/samples/08_PointOfInterest_1_PoiAtLocation/js/poiatlocation.js:50:30)<br />", source: https://www.wikitude.com/libs/architect.js (1)

saveCoordinates: function saveCoordinatesFn(poiData)

    {

        var singlePoi = {

            "id": poiData.id,

            "longitude": parseFloat(poiData.longitude),

            "latitude": parseFloat(poiData.latitude),

            "altitude": parseFloat(poiData.altitude),

            "description": poiData.description,

            "title": poiData.name

        };

        World.loadPoisFromJsonData(singlePoi);

    }


I am following this example and PoiDataFromApplicationModelExtension.java

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);

World.loadPoisFromJsonData(singlePoi);


final JSONArray jsonArray = generatePoiInformation(loc);

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

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


image


the document did not mention much to get it working, and there is no such example (SampleCamContentFromNativeActivity.java) 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?

Thanks,

Eva

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() + ")");

to

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