Start a new topic

wikitude.setLocation not firing AR.context.onLocationChanged?

I'm using wikitude.setLocation to inject location provided by 3rd party positioning service.

I'm doing this:

wikitude.loadARchitectWorld(function (url) {
	window.positionService.onchange = function (position) {
		alert(position.latitude + ',' + position.longitude + ',' + position.accuracy);
		wikitude.setLocation(position.latitude, position.longitude, position.altitude, position.accurary);
	};

and this:

AR.context.onLocationChanged = function (latitude, longitude, altitude, accurary) {
	AR.context.onLocationChanged = null;
	alert(latitude + ',' + longitude + ',' + accuracy);

but it turns out that AR.context.onLocationChanged does not follow immediately after location update, and the alert shows that the value received is different from the value provided by the positioning service, so I guess the mechanism is simply not working and wikitude is using location from GPS.

Am I doing wrong?

I'm using Cordova plugin 5.1.4.


Hi Jack,

Our last responses overlapped :) My last message was referring to the one from Feb 28, 10:40 AM.

Hi Jack,

You should be able so specify the accuracy in the Wikitude Cordova plugin JS API. The Android plugin tries to read it in line 410 - 426.


Best regards,

Andreas

Andreas,

410-426 is code for ACTION_CALL_JAVASCRIPT in v5.1.4 cordova plugin code, so I guess you are mentioning the code above it, which is the lines I pasted in my last post, specifically:

 

WikitudePlugin.this.architectView.setLocation( lat, lon, altitude, accuracy.floatValue() );
Seems it should work, however I'm always receiving 1, regardless of what I set in WikitudePlugin.setLocation. Maybe I'm making mistakes elsewhere, I'll try to repro it in a small demo.
Thanks!

Hi Jack,

regarding the line numbers: You might be right, I had a look at the 6.0 Cordova plugin. Below is the complete if statement that handles setting of new locations. You could log the `args` parameter and check what is is included for the accuracy.


 

		/* location update */
        if ( WikitudePlugin.ACTION_SET_LOCATION.equals( action ) ) {
            if ( this.architectView != null ) {
                try {
                    final double lat = args.getDouble( 0 );
                    final double lon = args.getDouble( 1 );
                    float alt = Float.MIN_VALUE;
                    try {
                        alt = (float)args.getDouble( 2 );
                    } catch ( Exception e ) {
                        // invalid altitude -> ignore it
                    }
                    final float altitude = alt;
                    Double acc = null;
                    try {
                        acc = args.getDouble( 3 );
                    } catch ( Exception e ) {
                        // invalid accuracy -> ignore it
                    }
                    final Double accuracy = acc;
                    if ( this.cordova != null && this.cordova.getActivity() != null ) {
                        this.useCustomLocation = true;
                        cordova.getActivity().runOnUiThread(
//						this.cordova.getThreadPool().execute(
                                new Runnable() {

                                    @Override
                                    public void run() {
                                        if ( accuracy != null ) {
                                            WikitudePlugin.this.architectView.setLocation( lat, lon, altitude, accuracy.floatValue() );
                                        } else {
                                            WikitudePlugin.this.architectView.setLocation( lat, lon, altitude );
                                        }
                                    }
                                } );
                    }

                } catch ( Exception e ) {
                    callContext.error( action + ": exception thrown, " + e != null ? e.getMessage() : "(exception is NULL)" );
                    return true;
                }
                callContext.success( action + ": updated location" );
                return true;
            } else {
				/* return error if there is no architect-view active*/
                callContext.error( action + ": architectView is not present" );
            }
            return true;
        }

 

Small demos are always good. If you find an issue, you can also send this small demo to us and we have a look at it.


Best regards,

Andreas

Login or Signup to post a comment