Geolocation and direction (or heading)



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, also the note that it was deprecated and use this plug instead nativescript-geolocation. Looking at that Github page ( 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

Thank you for your help.

exports.takePicture = function() {

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

        if (!geolocation.isEnabled()) {

        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)


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.