Start a new topic

setUseInjectedLocation() not working in iOS JS API

Hi,

I am using Wikitude SDK iOS JavaScript API  (version: 7.2.1 ) with Swift 3 and wanted to provide fixed location but this setUseInjectedLocation() method doesnt seem to work!

I am trying to set it to true in startWikitudeSDKRendering() as well as inside didFinishLoadArchitectWorldNavigation. 

Code snippet:


self.architectView?.setUseInjectedLocation(true);

 let location:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: Double(("12" as NSString).doubleValue), longitude: Double(("77" as NSString).doubleValue));

 if (self.architectView?.isUsingInjectedLocation())! 

{

 

 self.architectView?.injectLocation(withLatitude: location.latitude, longitude: location.longitude, altitude: 900, accuracy: 1);

 }


It never goes inside the if block!



I saw a similar post at - https://support.wikitude.com/support/discussions/topics/5000075538 but that also is not helpful.



1 person has this problem

Any help on this please, is there a bug in the SDK or need to implement it in a different way ?


Also, I tried a workaround to pass the coordinate directly in a custom JavaScript function using architectView?.callJavaScript( "xyz" ) to set the user location but that also doesn't work and the user location in AR view doesnt change to given location. Its still showing the POIs as per the location from GPS ( have disabled the user location updates inside locationChanged: function locationChangedFn(lat, lon, alt, acc) { } in the nativedetailscreen.js )  .


I am using Swift 3 and testing on iOS 9.


Thanks 



Hi,

Can you please try to first inject a location and then call `setUseInjectedLocation` to true?


You can only inject custom locations in the ObjC or Java layer of our SDK, not in the JS API.


Best regards,
Andreas Schacherbauer

Hi Andreas,


Thanks for getting back to me. Actually , I have tried it already and this also doesn't work.

I am using Swift 3 and testing on an iOS 9  device. I hope below is the sequence you are referring to -



 let location:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: Double(("12" as NSString).doubleValue), longitude: Double(("77" as NSString).doubleValue));
self.architectView?.injectLocation(withLatitude: location.latitude, longitude: location.longitude, altitude: 900, accuracy: 1);
self.architectView?.setUseInjectedLocation(true);

I have tried it in both  startWikitudeSDKRendering() as well as inside didFinishLoadArchitectWorldNavigation() methods but unfortunately cant get it to work. 


 Thanks

Sandeep


Hi Sandeep,

I just tried it and it works for me. Here is what I did:

* I took the Wikitude JS API example app for iOS (Written in ObjC)

* I modified the `WTAugmentedRealityViewController.m` file and added the following snippet:


dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [self.architectViewinjectLocationWithLatitude:10longitude:20accuracy:5];
    [self.architectViewsetUseInjectedLocation:YES];
 });


The snippet is placed in the completion handler of [WTArchitectView] -start:completion: (Line 325 in the before mentioned view controller).


I changed the file `poiatlocation.js` from example `08_PointOfInterest_1_PoiAtLocation` and added an alert (`alert('location changed: lat ' + lat + ' lon: ' + ' acc: ' + acc);`) at the beginning of the function `locationChanged` (line 58).


After the example started, I get the alert with my location after ~1 sec.


Can you try to reproduce my steps in the mentioned example app and depending on the outcome, either reply here or try to adapt those concepts to your app?


Best regards,
Andreas Schacherbauer

Login or Signup to post a comment