Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashing when onLocationChanged is used #40

Closed
RyanAfrish7 opened this issue May 26, 2018 · 3 comments
Closed

App crashing when onLocationChanged is used #40

RyanAfrish7 opened this issue May 26, 2018 · 3 comments

Comments

@RyanAfrish7
Copy link

Below is the code I took from the docs. It seems not working and throws a RuntimeException.

var location = new Location();

try {
  location.onLocationChanged.listen((location) {
    print(location);
  });
E/AndroidRuntime(26645): FATAL EXCEPTION: main
E/AndroidRuntime(26645): Process: br.co.carbucks.carbucks, PID: 26645
E/AndroidRuntime(26645): java.lang.RuntimeException: Location permission denied
E/AndroidRuntime(26645): 	at com.lyokone.location.LocationPlugin$2.onLocationResult(LocationPlugin.java:141)
E/AndroidRuntime(26645): 	at com.google.android.gms.internal.location.zzau.notifyListener(Unknown Source:4)
E/AndroidRuntime(26645): 	at com.google.android.gms.common.api.internal.ListenerHolder.notifyListenerInternal(Unknown Source:8)
E/AndroidRuntime(26645): 	at com.google.android.gms.common.api.internal.ListenerHolder$zza.handleMessage(Unknown Source:14)
E/AndroidRuntime(26645): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(26645): 	at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime(26645): 	at android.app.ActivityThread.main(ActivityThread.java:6494)
E/AndroidRuntime(26645): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(26645): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/AndroidRuntime(26645): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

So I digged a little deeper and found the part throwing this exception. These are the code from L127-L145 of LocationPlugin.java. Why should the condition be events == null and then a method success() of the events object being access later in the true block?

private void createLocationCallback() {
    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            if(events == null) {
                super.onLocationResult(locationResult);
                Location location = locationResult.getLastLocation();
                HashMap<String, Double> loc = new HashMap<String, Double>();
                loc.put("latitude", location.getLatitude());
                loc.put("longitude", location.getLongitude());
                loc.put("accuracy", (double) location.getAccuracy());
                loc.put("altitude", location.getAltitude());
                events.success(loc);
            } else {
                throw new RuntimeException("Location permission denied");
            }
        }
    };
}
@devsontx
Copy link

i have this issue too.

@GDur
Copy link

GDur commented May 29, 2018

I had the same issue and am now using a Timer.periodic + "var currentLocation = <String, double>{};

var location = new Location();

// Platform messages may fail, so we use a try/catch PlatformException.
try {
currentLocation = await location.getLocation;
} on PlatformException {
currentLocation = null;
}" workaround

@Lyokone
Copy link
Owner

Lyokone commented May 29, 2018

Should be fixed in 1.3.1, thank you for your time 👍

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

No branches or pull requests

4 participants