NativeScript App Location not available

8 posts, 0 answers
  1. Anton Swanevelder
    Anton Swanevelder avatar
    28 posts
    Member since:
    Aug 2008

    Posted 29 Apr 2015 Link to this post

    Hi,

    I am unable to get Location to work on NativeScript if I try to use the http://docs.nativescript.org/location examples.

    Reason​ I guess is that the app does not have Location services. Is this something that will be enabled in a newer version or am I missing something?

    Thanks,

    Anton

  2. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 30 Apr 2015 Link to this post

    Hello,

    I would suggest to take a closer look at dedicated help article for location. (In case you've missed it, we recently updated it).
    If you still cannot get a location please do not hesitate to contact us again.

    Regards,
    Nedyalko Nikolov
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
  3. Anton Swanevelder
    Anton Swanevelder avatar
    28 posts
    Member since:
    Aug 2008

    Posted 30 Apr 2015 in reply to Nedyalko Nikolov Link to this post

    Hi Nedyalko,

    Thanks for your response. 

    Could you possibly have a look at this code and let me know if I am doing something stupid? The HowTo looks very simple but I fear that I am missing some code that will tell iOS to allow LOCATION.

    var observable = require("data/observable");
     
    // Event handler for Page "loaded" event attached in main-page.xml
    function pageLoaded(args) {
        var page = args.object;
     
        var locationModule = require("location");
        var locationManager = new locationModule.LocationManager();
        var locationOptions = {
            desiredAccuracy: 3,
            updateDistance: 0,
            minimumUpdateTime: 5000,
            maximumAge: 20000
        };
         
        page.bindingContext = { location: 'Busy...' };
         
        locationManager.startLocationMonitoring(function(location) {
            page.bindingContext = { location: 'Location received: ' + location };
            }, function (error) {
                page.bindingContext = { location: 'Location error received: ' + error };
        }, locationOptions);
         
    }
    exports.pageLoaded = pageLoaded;

  4. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 05 May 2015 Link to this post

    Hi,

    Most probably you are using iOS 8.0+. There is a change regarding location services.

    I'm pasting part of our documentation:

    Note (iOS): For iOS there is a change introduced in 8.0 version that changes the way location service is requested. There are two modes for using location service from an application (WhenInUse - denotes using location service only when application is running, and Always mode which allows using location service in a background application). According to business scenario location service request could be done via requestWhenInUseAuthorization or requestAlwaysAuthorization methods. Both methods require a specific setting in your application to be set in application.plist file. Application plist file should contain NSLocationWhenInUseUsageDescrition or NSLocationAlwaysUsageDescription string values respectively. For iOS versions below 8.0 there is a similar string value named NSLocationUsageDescription which is not mandatory.

    If there is no string that describes why application wants to use location services, location services will not be granted with iOS 8.0+.

    Regards,
    Nedyalko Nikolov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  5. Martynas
    Martynas avatar
    1 posts
    Member since:
    Nov 2015

    Posted 05 Jan Link to this post

    hey, does this works wirh nativescript companion app? Because I can't get location services enabled even when I added these strings in Info.plist and requested to register for location services.

    var iosLocationManager = CLLocationManager.alloc().init();
    iosLocationManager.requestWhenInUseAuthorization();
    iosLocationManager.requestAlwaysAuthorization();

  6. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 07 Jan Link to this post

    Hi,

    We recently deprecated built-in "location" module and replaced it with a plugin called "nativescript-geolocation". This plugin is available on "www.npmjs.com". For more information how to use this plugin you can take a look at this help topic. Within help article there is a link to a real example which I also paste it here for convenience.

    Please let me know if there is something unclear.

    Regards,
    Nedyalko Nikolov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Tigga
    Tigga avatar
    5 posts
    Member since:
    Feb 2015

    Posted 01 Apr in reply to Nedyalko Nikolov Link to this post

    Is there a place to submit issues with the plugin. I was debugging the fact that it would not work in iOS 9 and I found this little bit of hardcoded information that causes it to fail.

    function enableLocationRequest(always) {
        if (platformModule.device.osVersion.indexOf("8") === 0)
        {
            var iosLocationManager = CLLocationManager.alloc().init();
            if (always) {
                iosLocationManager.requestAlwaysAuthorization();
            }
            else {
                iosLocationManager.requestWhenInUseAuthorization();
            }
        }
    }

    As you can see, if the OS version is 9, then it will skip this code. However, 9 still requires the same checks that 8 does.

    This is using the latest version available. Version 0.0.8

  8. nikolay.tsonev
    Admin
    nikolay.tsonev avatar
    70 posts

    Posted 04 Apr Link to this post

    Hello,
    Thank you for your question.

    You can submit issues about this plugin in its repository in github.
    https://github.com/NativeScript/nativescript-geolocation/issues
    Actually I found that similar issue exists. This problem is scheduled for fixing.
    The fix will be available in the new update of the plugin. 

    Let me know whether this helps.
    Regards,
    nikolay.tsonev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top