This is a migrated thread and some comments may be shown as answers.

NativeScript App Location not available

7 Answers 176 Views
Apple iOS
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Anton Swanevelder
Top achievements
Rank 2
Anton Swanevelder asked on 29 Apr 2015, 01:56 PM

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

7 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 30 Apr 2015, 06:56 AM
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.

 
0
Anton Swanevelder
Top achievements
Rank 2
answered on 30 Apr 2015, 10:20 AM

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;

0
Nedyalko Nikolov
Telerik team
answered on 05 May 2015, 11:07 AM
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.

 
0
Martynas
Top achievements
Rank 1
answered on 05 Jan 2016, 01:03 PM

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();

0
Nedyalko Nikolov
Telerik team
answered on 07 Jan 2016, 02:27 PM
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
0
Tigga
Top achievements
Rank 1
Iron
answered on 01 Apr 2016, 04:28 PM

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

0
Nikolay Tsonev
Telerik team
answered on 04 Apr 2016, 12:32 PM
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
Tags
Apple iOS
Asked by
Anton Swanevelder
Top achievements
Rank 2
Answers by
Nedyalko Nikolov
Telerik team
Anton Swanevelder
Top achievements
Rank 2
Martynas
Top achievements
Rank 1
Tigga
Top achievements
Rank 1
Iron
Nikolay Tsonev
Telerik team
Share this question
or