Start a new topic

AR not found PhoneGap

Hi,

I am following the guides from the wikitude cordova documentation. When I am running my application, I am getting an error when trying to load a AR object. The actual error code I get is:

[console.log] Error in Success callbackId: WikitudePlugin1329171891 : ReferenceError: AR is not defined

explore.html
`

<script src="https://www.wikitude.com/libs/architect.js"></script>

    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/explore.js"></script>
    <title>Explore</title>
</head>
<body>
   
    
</body>

`

explore.js
`var app = {

//true once data is fetched
initiallyLoadedData: false,

//POI-Marker Assets
markerDrawable_idle: null,

//URL/Path to the augmented reality experience you would like to load
arExperienceUrl: "../explore.html",

//The features your augmented reality experience requires, only define the ones you really need
requiredFeatures: ["2d_tracking", "geo"],

//Represents the device capabilities of launching AR experiences with specific features
isDeviceSupport: false,

//Additional startup settings, for now the only setting available is camera_position
startupConfiguration:
{
	"camera_position": "back"
},

// Application Constructor
initialize: function() {
    this.bindEvents();
},

bindEvents: function(){
	document.addEventListener('deviceready', this.onDeviceReady, false);
},

// deviceready Event Handler
//
// Bind any cordova events here. Common events are:
// 'pause', 'resume', etc.
onDeviceReady: function() {
    app.wikitudePlugin = cordova.require("com.wikitude.phonegap.WikitudePlugin.WikitudePlugin");
    app.wikitudePlugin.isDeviceSupported(app.onDeviceSupported, app.onDeviceNotSupported, app.requiredFeatures);
},

onDeviceSupported: function(){
	alert("Device Supported");
	app.wikitudePlugin.loadARchitectWorld(
		app.onARExperienceLoadedSuccessful,
		app.onARExperienceLoadError,
		app.arExperienceUrl,
		app.requiredFeatures,
		app.startupConfiguration
	);
},

onDeviceNotSupported: function(errorMessage){
	alert("No support for device: " + errorMessage);
},

loadPoisFromJsonData: function(poiData){
	alert(poiData.latitude + " : " + poiData.longitude);
	// start loading marker assets
	app.markerDrawable_idle = new AR.ImageResource("../assets/marker_idle.png");
	
	var markerLocation = new AR.GeoLocation(poiData.latitude, poiData.longitude, poiData.altitude);
	var markerImageDrawable_idle = new AR.ImageDrawable(markerDrawable_idle, 2.5, {
		zOrder: 0,
		opacity: 1.0
	});
	
	//create GeoObject
	var markerObject = new AR.GeoObject(markerLocation, {
		drawable:{
			cam: [markerImageDrawable_idle]
		}
	});
	
	
	console.log('1 place loaded');
},

onARExperienceLoadedSuccessful: function(loadedURL){
	alert("AR experience loaded");
	
	// request data if not already present
	if(!app.initiallyLoadedData){
		var poiData = {
			"id": 1,
			"longitude": 2.992115,
			"latitude": 55.959722,
			"altitude": 100.0
		};
		app.loadPoisFromJsonData(poiData);
		app.initiallyLoadedData = true;
	}
	
},
onARExperienceLoadError: function(errorMessage){
	alert("Error in Loading AR experience: " + errorMessage);
}

};

app.initialize();`



Hi,


Is there anyone able to help with this issue? I am using this as part of a University project and need to resolve this issue quickly to stay on schedule.

Good morning David, 



I believe


<script src="https://www.wikitude.com/libs/architect.js"></script>


should be in the HTML file of your actual AR world, not in the HTML file of your Cordova application. Failing to find the architect.js file would explain the AR object not being available.


Here is one such AR world HTML file as a reference.



- Daniel

Hi Daniel,

Thanks for the reply.


I have tried placing the link in my AR world an I am still getting the same issue. Am I doing something wrong with JS code as to why it not picking it up?


David

Hi David,



I'm afraid I won't have the time to take thorough look at your code before Monday. What I can provide, for now, is the relevant files of an application I know to be working correctly. Maybe comparing your code thereto could help you find out what's wrong.


I attached the files to this post.


I could image that the following line is what you're missing in your HTML file.


<meta http-equiv="Content-Security-Policy" content="default-src * gap://ready file:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">



- Daniel


html
(10.4 KB)
js
(7.23 KB)

Hi Daniel,


Thanks for the files, I will have a look at them and see if I can fix the issue. I have attached my code for you to look at in your own time. I will let you know if I solved my issue and look forward to hearing your response.


David Dryburgh

js
(2.86 KB)
html
(601 Bytes)
html
(1.18 KB)
Login or Signup to post a comment