question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when trying to enable location service on Android

See original GitHub issue

Hi, When I’m trying to enable location service I got this error:

03-13 11:33:47.250 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.dispatchCallJSMethodNative(int, java.lang.String, boolean, long, java.lang.Class, java.lang.Object[]) (Runtime.java:1084)
03-13 11:33:47.250 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethodImpl(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[]) (Runtime.java:966)
03-13 11:33:47.250 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[]) (Runtime.java:953)
03-13 11:33:47.250 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, java.lang.Object[]) (Runtime.java:937)
03-13 11:33:47.250 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, java.lang.Object[]) (Runtime.java:929)
03-13 11:33:47.251 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethodNative(int, int, java.lang.String, int, boolean, java.lang.Object[]) (Runtime.java:-2)
03-13 11:33:47.251 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.dispatchCallJSMethodNative(int, java.lang.String, boolean, long, java.lang.Class, java.lang.Object[]) (Runtime.java:1084)
03-13 11:33:47.251 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethodImpl(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[]) (Runtime.java:966)
03-13 11:33:47.251 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[]) (Runtime.java:953)
03-13 11:33:47.251 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, java.lang.Object[]) (Runtime.java:937)
03-13 11:33:47.251 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, java.lang.Object[]) (Runtime.java:929)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethodNative(int, int, java.lang.String, int, boolean, java.lang.Object[]) (Runtime.java:-2)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.dispatchCallJSMethodNative(int, java.lang.String, boolean, long, java.lang.Class, java.lang.Object[]) (Runtime.java:1084)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethodImpl(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[]) (Runtime.java:966)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[]) (Runtime.java:953)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, java.lang.Object[]) (Runtime.java:937)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, java.lang.Object[]) (Runtime.java:929)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethodNative(int, int, java.lang.String, int, boolean, java.lang.Object[]) (Runtime.java:-2)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.dispatchCallJSMethodNative(int, java.lang.String, boolean, long, java.lang.Class, java.lang.Object[]) (Runtime.java:1084)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethodImpl(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[]) (Runtime.java:966)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, long, java.lang.Object[]) (Runtime.java:953)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, boolean, java.lang.Object[]) (Runtime.java:937)
03-13 11:33:47.255 10726 10726 I art     :   at java.lang.Object com.tns.Runtime.callJSMethod(java.lang.Object, java.lang.String, java.lang.Class, java.lang.Object[]) (Runtime.java:929)
  • Android 7.0.0 Real device (Sony Xperia Z5)

  • CLI: 3.4.3

  • Cross-platform modules: 3.3.0

  • Runtime(s): "tns-android":3.3.0 and "tns-ios":3.3.0

  • Plugin(s):

"dependencies": {
    "nativescript-barcodescanner": "^2.7.4",
    "nativescript-carousel": "^3.1.1",
    "nativescript-dom": "^2.0.0",
    "nativescript-fancyalert": "^1.1.2",
    "nativescript-filter-select": "^1.2.2",
    "nativescript-fonticon": "^1.1.1",
    "nativescript-geolocation": "^4.2.3",
    "nativescript-google-maps-sdk": "^2.5.0",
    "nativescript-iqkeyboardmanager": "^1.2.0",
    "nativescript-loading-indicator": "^2.4.0",
    "nativescript-master-technology": "^1.1.1",
    "nativescript-modal-datetimepicker": "^1.0.3",
    "nativescript-phone": "^1.3.1",
    "nativescript-pro-ui": "^3.4.0",
    "nativescript-theme-core": "~1.0.2",
    "nativescript-web-image-cache": "^4.2.2",
    "tns-core-modules": "~3.3.0"
  },
  "devDependencies": {
    "babel-traverse": "6.26.0",
    "babel-types": "6.26.0",
    "babylon": "6.18.0",
    "lazy": "1.0.11",
    "nativescript-dev-typescript": "~0.5.0",
    "typescript": "~2.4.2"
  }

I just added the plugin and copied the code from the demo:

export function enableLocation() {
    return new Promise((resolve,reject)=>{
        geolocation.isEnabled().then(function (isEnabled) {
            if (!isEnabled) {
                console.log('location is not enabled... try enabling');
                geolocation.enableLocationRequest().then(function () {
                    console.log('location is  enabled now!');
                    resolve();
                }, function (e) {
                    console.log('location failed to be enabled');
                    reject(e);
                });
            }
            else{
                console.log('location is  enabled');
                resolve();
            }
        }, function (e) {
            reject(e);
        });
    });
}
export function getLocation() {
    return new Promise((resolve,reject)=>{
        this.enableLocation().then(()=>{
            geolocation.getCurrentLocation({
                desiredAccuracy: Accuracy.high,
                maximumAge: 10000,
                updateDistance: 0.1,
                timeout: 20000
            })
                .then(function (loc) {
                    if (loc) {
                        console.dir(loc)
                        resolve(loc)
                    }
                }, function (e) {
                    reject(e);
                });
        }).catch((e)=>{
            reject(e);
        })
        
    })
}

it’s trying to enable the service but get the pasted error, and execute catch

console.log('location failed to be enabled');
                    reject(e);

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tgpetrovcommented, Mar 15, 2018

@OPADA-Eng, thank you for providing a sample project. You are experiencing this issue in Android Runtime. You can update the version of tns-android in your app’s package.json to 3.3.1 or newer and you should be able to get the correct location.

0reactions
linicommented, Oct 30, 2018

If you still experience this with the current 4.2 NativeScript android runtime, please open a new issue and follow the instructions presented in the issue template so we can have as much information as possible to help diagnose and solve it. Thanks in advance!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 6 Ways to Fix Location Services Not Working on Android
Step 1: Open the Settings app on your phone and scroll down to tap on Location. Step 2: Go to Location services and...
Read more >
Manage your Android device's location settings
Swipe down from the top of the screen. · Touch and hold Location . If you don't find Location : Tap Edit or...
Read more >
How to fix a location unavailable error in the Android device ...
One of the solution is:- Update your Google Play Services to latest fix. Go to settings, in that app manager and find Google...
Read more >
How to: Enable Location Services on your Android Device ...
Access your Android Settings menu. Select Location Services. Turn on "Allow Access to my Location." Enable Wireless networks. Enable GPS ...
Read more >
11 methods to fix Android GPS not working - Carlcare
If you're trying to get your location data on apps that require the internet, like Google Maps, be sure if you have an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found