Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Geolocation: How to get prompt to use Location Services instead of 'kCLErrorDomain' error

Hi,

In the midst of testing my app in various modes with Geolocation, I find that most things work but when my app's specific Location Services setting is turned off, it's bombing with a "Domain=kCLErrorDomain Code=1" error – rather than asking if the app can use Location Services. Here's the code:


    GetLocation.prototype.get_location = function () {
        if (Titanium.Geolocation.locationServicesEnabled == false) {
            Titanium.UI.createAlertDialog({
                title:'myApp',
                message:'You must have Location Services turned on to use this feature.'
            }).show();
            return;
        } else {

            if (me.isSimulator) {
                me.callback(me.latitude,me.longitude);            
            }

            Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;

            Titanium.Geolocation.distanceFilter = 10;
            Ti.Geolocation.purpose = "Recieve User Location";

            Titanium.Geolocation.getCurrentPosition(function(e) {
                if (e.error) {
                    alert('Error: ' + JSON.stringify(e.error));
                    return;
                }
            });

            Titanium.Geolocation.addEventListener('location',function(e) {
                me.longitude = e.coords.longitude;
                me.latitude = e.coords.latitude;

                //*** Callback routine
                me.callback(me.latitude,me.longitude);
            });
        }
    };

Any idea of what's wrong – or is there a better way to do this?

Thanks in advance,

Mark

— asked November 2nd 2010 by Mark Pemburn
  • geolocaton
  • iphone
  • kclerrordomain
0 Comments

1 Answer

  • Mark,

    I'm not sure how to ask the user for permission again, however I do know how to kill that pesky error alert. It is being caused by this chunk of code:

           Titanium.Geolocation.getCurrentPosition(function(e) {
               if (e.error) {
                   alert('Error: ' + JSON.stringify(e.error));
                   return;
               }
           });
    

    I had the same problem and I replaced the alert() with a Ti.API.error() console message.

    As for asking for permission to use the location services again, I think that there may be a solution to this in v1.5.0. Someone from Appcelerator referred me to this ticket regarding a new function called Ti.Geolocation.restart(). I'm not going to upgrade my app to v1.5 soon so I can't test it but let me know if you solve the puzzle.

    Cheers,
    Brandon

    — answered December 13th 2010 by Brandon Jackson
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.