Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

LocationRequest() from plugin crash the app [BUG] #259

Open
vforv opened this issue Apr 10, 2020 · 5 comments
Open

LocationRequest() from plugin crash the app [BUG] #259

vforv opened this issue Apr 10, 2020 · 5 comments

Comments

@vforv
Copy link

vforv commented Apr 10, 2020

After I call this

Geolocation.enableLocationRequest().then(() => {
      Geolocation.getCurrentLocation({}).then(location => {
        console.log(location)
      }).catch(error => {
        console.log(error)
      });
  });

App just crash... No any log displayed after crush

Using nativescript 6.5.0 with Angular 8.0

I am using also Android device with wifi and geolocation on

UPDATE

After debugging I found line which crash the app it is 91 function _getLocationRequest(options)
var mLocationRequest = new com.google.android.gms.location.LocationRequest()

@vforv vforv changed the title Plugin just crash the app LocationRequest() from plugin crash the app [BUG] Apr 10, 2020
@Cloudxyz
Copy link

I have this issue too, i not found the line, because i dont know where search

@juanpicuervo
Copy link

I have this issue too, i cannot use this feature :(

@vforv
Copy link
Author

vforv commented Apr 29, 2020

add this to the app.gradle

project.ext {
       googlePlayServicesVersion = "15.0.1"
}
dependencies {
   def googlePlayServicesVersion = project.googlePlayServicesVersion
   compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
}

@neil-119
Copy link

neil-119 commented Jun 4, 2020

Adding on to vforv's answer, I created a file called before-plugins.gradle in the same directory as app.gradle and added in the following content (NativeScript loads the file automatically):

android {
    project.ext { 
        googlePlayServicesVersion = "16.+"
    }
    dependencies {
        def googlePlayServicesVersion = project.googlePlayServicesVersion
        compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
    }
}

This solved it for me.

@aosi87
Copy link

aosi87 commented Jun 22, 2020

I found that it could be a combination of things, please make sure to include this information in the readme:

If you guys installed this using the companion app (Nativescript-sidekick) you will find that you MUST use the tool to install dependencies and plugins, if for some reason you switch to the CLI, make sure to delete and recreate your configurations, looks like the files created by these are different.

So in my case:

  • Added these lines into AndroidManifest.xml:
	<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
	<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

In theory, these permissions should be included automatically.

Now, this didn't solve my problem, I use a combination of GoogleMaps and Geolocalization, and other plugins, these plugins set up or add/use configurations of GooglePlayServices, this is a problem, it means we need to match the version of the services, in this case, I will use the nice hook that @neil-119 uses, ( i didn't know Nativescript handles before, after plugins.). This makes my configuration work.

Now, something I found by playing around:

You can do this:

Geo.enableLocationRequest();
Geo.getCurrentLocation(
{ desiredAccuracy: Accuracy.high/any, maximumAge: 5000, timeout: 10000 }
           ).then((result) => {
                console.log(JSON.stringify(result));
            })
            .catch((err) => {
                console.log("loc error", err);
            });

And also this:

Geo.enableLocationRequest(true)
        .then(() => {
            Geo.isEnabled().then(isLocationEnabled => {
                console.log('result is '+isLocationEnabled);
                if(!isLocationEnabled) {
                    return;
                }

                Geolocation.getCurrentLocation({}) // default
                .then(result => {
                    console.log('loc result', result);
                })
                .catch(e => {
                    console.log('loc error', e);
                });
            });
        });

I hope this solves problems and speeds up your dev, it took me almost a day to find these problems for my current configuration. Cheers.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants