capacitor-community / background-geolocation

A Capacitor plugin that sends you geolocation updates, even while the app is in the background.
MIT License
177 stars 54 forks source link

Does it conflicts with capacitor/geolocation? #113

Closed HammasMajeed closed 3 months ago

HammasMajeed commented 4 months ago

My app was using @capacitor/geolocation. The only purpose was to get current location of user. After that I needed to get the location continuously in background also. The problem arose when capacitor-community/background-geolocation integrated with code run on Android . It was working fine in iOS. But in android it is giving: Caused by: java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.location.FusedLocationProviderClient, but class was expected (declaration of 'com.google.android.gms.location.FusedLocationProviderClient' appears in /data/app/~~T4_h8WPsBF1KaVyZb0o7JQ==/io.ionic.mbntasker-wmKD2k-rrZemGe7I-LpPKQ==/base.apk) at com.capacitorjs.plugins.geolocation.Geolocation.sendLocation(Geolocation.java:51) at com.capacitorjs.plugins.geolocation.GeolocationPlugin.getPosition(GeolocationPlugin.java:155) at com.capacitorjs.plugins.geolocation.GeolocationPlugin.getCurrentPosition(GeolocationPlugin.java:86)

with little research I found that there is a mismatch between the expected type of a class/interface and the actual type encountered at runtime. In this case, the code is expecting a class but found an interface instead. Specifically, the error occurs in the Geolocation plugin within my Android app.

To Reproduce: Steps to reproduce the behavior:

  1. Use @capacitor/geolocation
  2. Get the current position using Geolocation.getCurrentPosition
  3. Now import capacitor-community/background-geolocation
  4. Run ionic capacitor run android on physical device
  5. When app is trying is get current location from Geolocation.getCurrentPosition it will be crashed

Smartphone

diachedelic commented 4 months ago

Do you think they can work together? You are the expert at this point.

HammasMajeed commented 4 months ago

I think they should work together.. But it is Java coding issue. I am no expertise in Java :(.. I can remove @capacitor/geolocation from my code because it is being used for getting current location only. If capacitor-community/background-geolocation can also give current location without adding a watcher. This will be a way to solve this problem.. But I did not find any method to get current location only in documentation. Can you suggest how can I do that?

diachedelic commented 4 months ago

The method in the documentation is valid. Have you tried it?

HammasMajeed commented 3 months ago

Hi! This issue resolved when I updated my project to capacitor version 5. Thanks