How to work with GeoLocation Class

 

If you want to place an augmented object at any kind of location then you would need to use GeoLocation services. When working with Geo locations you can choose either RelativeLocation (and this is what we implement in our samples) or GeoLocation. If you refer to our documentation here you will find an example of Location Strategy.


The concept of RelativeLocation is that they are always relative to the current user location and this is why we prefer these when we need to test. Therefore, you can simply refer to our documentation and browse through the many samples we are offering to implement RelativeLocation features.


GeoLocations are fixed to a certain latitude/longitude coordinate and stay at exact this place. In order to make sure that you have specified the correct coordinates when working with GeoLocations you can also advice these websites to Convert Lat and Long to Address and to Get Latitude and Longitude.


Since all the sample we offer in our documentation implement the RelativeLocation class, we provide here a sample code to work with GeoLocation. Please keep in mind that you need to change the latitude and longitude values used in this example to your own values.

 

 

 var World = {
loaded: false,
rotating: false,
init: function initFn() {
this.createModelAtLocation();
},

createModelAtLocation: function createModelAtLocationFn() {
/*
First a location where the model should be displayed will be defined. This location will be relativ to the user.
*/
var location = new AR.GeoLocation(47.805634, 13.045209);
var altitude = location.altitude;

/*
Next the model object is loaded.
*/
var modelEarth = new AR.Model("assets/earth.wt3", {
onLoaded: this.worldLoaded,
scale: {
x: 1,
y: 1,
z: 1
}
});

var indicatorImage = new AR.ImageResource("assets/indi.png");
var indicatorDrawable = new AR.ImageDrawable(indicatorImage, 0.1, {
verticalAnchor: AR.CONST.VERTICAL_ANCHOR.TOP
});

/*
Putting it all together the location and 3D model is added to an AR.GeoObject.
*/
var obj = new AR.GeoObject(location, {
drawables: {
cam: [modelEarth],
indicator: [indicatorDrawable]
}
});
},

worldLoaded: function worldLoadedFn() {
World.loaded = true;
var e = document.getElementById('loadingMessage');
e.parentElement.removeChild(e);
}
};
/* Set a custom function where location changes are forwarded to. There is also a possibility to set AR.context.onLocationChanged to null. In this case the function will not be called anymore and no further location updates will be received. */
AR.context.onLocationChanged = World.locationChanged;

World.init();

 

 

 When you are testing GeoLocation features, you need to keep in mind that the results could be greatly influenced by these two factors:

  • Testing inside. This could deteriorate the performance and therefore, it is always advisable to test outside.
  • GPS provider. You need to make sure that the GPS provider you are using is accurate enough and it does not influence the performance.


With SDK version 6.1 we included another option property, the "rotate.global" attribute of a Drawable. Setting rotatesToCamera to false and setting the rotate.global attribute accordingly should be able to allow you to place the model and make it face to the direction you wish to.


1 person likes this