Start a new topic

Location Based AR problem in android native javascript

Hii there,

     I have used the wikitude SDK to implement the location based AR in my . i have successfully implemented wikitude SDK in my application and also able to run the whole wikitude's example project but i have one problem with it can't able to find the solution for that because i am native android developer so don't have much idea on javascript but still have done all the thing in javascript in my app

Problem is , i have set one latitude  and longitude of one place statically where i want to place the marker but marker moves everywhere when i move it's not stay at particular latitude and logitude . it's moving whenever i move can you please help me on this , because really stuck on this thing?

Hello Dharmesh,

When working with Geo locations you can choose either RelativeLocation (and this is what we implement in our samples) or GeoLocation. 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. GeoLocations are fixed to a certain latitude/longitude coordinate and stay at exact this place. If I understood correctly your use case then, I would work with GeoLocation.

I hope this helps

hello , 


       Thanks for a quick reply , yes have use GeoLocation , setting my location dynamically by using java code   

architectView.setLocation(Double.parseDouble(mLatitude), Double.parseDouble(mLongitude), location.getAltitude(), accuracy);

 this code can't showing the marker anywhere so after that what i done is created my own function in java script below is the code


MyDemo: function MyDemoFn(lat,lon,description) {

    			The custom function World.onLocationChanged checks with the flag World.initiallyLoadedData if the function was already called. With the first call of World.onLocationChanged an object that contains geo information will be created which will be later used to create a marker using the World.loadPoisFromJsonData function.

    		if (!World.initiallyLoadedData) {
            var poiData={
            "id": 1,
            				"longitude": (parseFloat(lon) + (Math.random() / 5 - 0.1)),
            				"latitude": (parseFloat(lat) + (Math.random() / 5 - 0.1)),
            				"altitude": 100.0,
            				"description": "",
            				"title": ""

            			World.initiallyLoadedData = true;


and in java code calling this method by this way 


architectView.callJavascript("World.MyDemo('" + mLatitude + "','" + mLongitude + "', '" + MyMemoryImage + "','" + MyMediaType + "')");

 this is displaying the marker but as i said it's moving with me whenever i move . and yes one more thing have tried by passing a static latitude and longitude in wikitude android javascript native example too but happend same thing . please can you help me with this? thanks..

Hiii here is the code of marker.js which i am using . on this code marker is still moving with me everywhere


function Marker(poiData) {

    this.poiData = poiData;

    var markerLocation = new AR.GeoLocation(22.996588,72.498665, poiData.altitude);

    this.markerDrawable_idle = new AR.ImageDrawable(World.markerDrawable_idle, 10, {
        zOrder: 0,
        opacity: 1.0,
         onClick: Marker.prototype.getOnClickTrigger(this)

this.markerDrawable_play = new AR.ImageDrawable(World.markerDrawable_play, 2, {
        zOrder: 1,
        opacity: 1.0

    this.titleLabel = new AR.Label(poiData.title.trunc(10), 1, {
        zOrder: 1,
        translate: {
            y: 0.55
        style: {
            textColor: '#00000000',
            fontStyle: AR.CONST.FONT_STYLE.BOLD


    this.descriptionLabel = new AR.Label(poiData.description.trunc(15), 0.8, {
        zOrder: 1,
        translate: {
            y: -0.55
        style: {
            textColor: '#00000000'

    // Changed: 
    this.markerObject = new AR.GeoObject(markerLocation, {
        drawables: {
            cam: [this.markerDrawable_idle,this.markerDrawable_play, this.titleLabel, this.descriptionLabel]

    return this;
Marker.prototype.getOnClickTrigger = function(marker) {

        The setSelected and setDeselected functions are prototype Marker functions.
        Both functions perform the same steps but inverted.

    return function() {

//        if (!Marker.prototype.isAnyAnimationRunning(marker)) {
//            if (marker.isSelected) {
//                Marker.prototype.setDeselected(marker);
//            } else {
//                Marker.prototype.setSelected(marker);
//                try {
//                    World.onMarkerSelected(marker);
//                } catch (err) {
//                    alert(err);
//                }
//            }
//        } else {
//            AR.logger.debug('a animation is already running');
//        }

 try {
                } catch (err) {
        return true;
// will truncate all strings longer than given max-length "n". e.g. "foobar".trunc(3) -> "foo..."
String.prototype.trunc = function(n) {
    return this.substr(0, n - 1) + (this.length > n ? '...' : '');


i am attaching a screenshot too

hi there ,

      again i tried with different locations , and  have set the marker's location to 1 KM away from my location but i can see the marker around me , and it 's moving with me even i crossed that location but the marker still appearing everywhere , i tried a lot but as i said i am native android app developer so don't have so much idea on javascript code . my client is going to purchase the wikitude full version once i successfully implement  this thing and give a demo to them . can you please help me with this . any help will appreciate thanks.. 

Hello Dharmesh,

From a quick look, your code seems to be ok since you are, indeed, using GeoLocation. Could you please test outside to see if this makes any difference?



hii thanks for reply , okay let me check by going outside will let you know the result thanks..

Hello have done the testing outside but what happened is marker is displaying good and it goes back while i cross the location too. but the problem is the marker is always follows me. is there any where that when i will reach  near marker , it zooming in slowly  and when go far zoom out that memory and after some distance it will be disappear  , i hope you got me.. thanks

Good morning,

could you describe in some more detail what you mean by "following you"?

Does it follow you as you move towards and away from the marker? Such that it always stays at the exact same size no matter how close you are? Or is it following your view as well, such that it is always in view independently of which direction you are looking in?

Also, where do you get the latitude and longitude values for architectView.callJavascript from?

- Daniel

Hello, thanks for the reply ,  yes it follows me as i move towards and away from marker . i just want like ARKit working in iOS that marker should not move from the latitude and longitude where it fixed. also i am passing the latitude and longitude from java native code and it's a static value assigned in that variable.

hello , 

First of all let me introduce my self and company , 

we are , leading AR and VR development Service provider in the UK , many of the clients of ours are in need of these services from us , 

time to time based on the clients requirements we suggest them the third party SDKs for the specific range of the features , 

so far we are really impressed with the Geo location based Ar functionality your SDK provides , 


Only problem we are facing right now is whenever you are being passed by the AR marker in AR view it supposed to get smaller when you go far from that marker , if you are few miles away from the marker it should get smaller and when you are getting closer it should get bigger in size , 

this is the only feature we are struggling to add since last few days and which is really important to add in the app we are building right now , 

there are other inquiries which requires the similar kind of solution , if you can speed up the communication and give us some more detailed explanation on how we can achieve this that will be really helpful , 

Kind Regard


Good morning,

the scaling behaviour of drawables attached to geo objects can be controlled with a set of scaling factors.




The intention of these factors is to allow drawables to maintain practical size for very close and very far distances. I'm afraid they can not be disabled entirely, but setting appropriate values should allow most use cases.

- Daniel

Hello thanks for reply , yes i have an idea on scaling factors , but don't know how to apply that scaling factor run time in OnLocationChanged method. like have already added the marker and want to change it's size so in on Location changed method don't know how to apply that changes.. can you help me with that please and if possible can you suggest me any example if any if you have ? thanks...

Good morning,

these factors are global constants, you do not need to apply them whenever the location changes. You can simply set them once, anywhere in your JavaScript code and the markers will scale accordingly. Like so:

// scaling value of 1 between 0 meters and 1 meters from the marker
// linear scaling starts at this distance
AR.context.scene.minScalingDistance = 1;

// scaling value of AR.context.scene.scalingFactor at 50km and more distance
// linear scaling stops at this distance
AR.context.scene.maxScalingDistance = 50000;

// the scaling factor at maxScalingDistance
// this is the smallest scaling applied
AR.context.scene.scalingFactor = 0.001;

Hope that helps.

- Daniel

Login or Signup to post a comment