Geolocation and direction (or heading)

plugins

#1

So I am attempting to get the location (latitude, longitude, and direction or bearing) after a user taps on a Take Picture button. Taping on the button simply triggers the exports.takePicture function (below). However, it is random as to what bearing it receives. Most of the time it is -1 but it seems that sometimes it does get me a course (however, that course does not match what my iOS compass says for example it will say 141 Degrees where my compass says 270 Degrees). I did find that I only had one bar, but I was also connected via wifi. My iOS compass works as expected.

I did take a look at this page https://docs.nativescript.org/hardware/location, also the note that it was deprecated and use this plug instead nativescript-geolocation. Looking at that Github page (https://github.com/NativeScript/nativescript-geolocation) it does not appear to have a direction so is direction not available or is my code below wrong. I can reliably get the latitude and longitude.

Do I need to create a custom plugin to read from the iOS compass and not use geolocation?

tns --version
3.2.0-2017-08-29-9791

Thank you for your help.

exports.takePicture = function() {
  camera.requestPermissions();

  if (isAvailable) {
    camera.takePicture()
      .then(function (img) {
        var lat;
        var long;
        var bearing;

        if (!geolocation.isEnabled()) {
          geolocation.enableLocationRequest()
        }

        let source = new imageSourceModule.ImageSource();

        source.fromAsset(img).then((newSource) => {
          if (geolocation.isEnabled()) {
            var loc = geolocation.getCurrentLocation( {desiredAccuracy: 1, timeout: 5000} ).then(function (location) {
              if (location) {
                lat = location.latitude;
                long = location.longitude;
                bearing = location.direction;

                console.log("bearing: " + bearing);
              }
            }).then(function() {
              if (lat && long && (bearing != -1)) { (etc)


#2

Did you ever find a resolution to this issue? I’m starting a new project that also needs to capture the bearing when a user takes a picture. We would like to use Nativescript but it could be an issue if this functionality is not available.