6

i am using geolocator in flutter project to get current location but this error come on it. i added all dependencies in both ios and android files still get this error i dont know why flutter channel stable, 2.12,

here is my code:

Position position = await Geolocato.getCurrentPosition( desiredAccuracy: LocationAccuracy.high);

here is my error coming which i tested android 10, 8 also, but answer same

Unhandled Exception: MissingPluginException(No implementation found for method getCurrentPosition on channel flutter.baseflow.com/geolocator)

i am using geolocator plugin here is plugin link :https://pub.dev/packages/geolocator

Adnan haider
  • 553
  • 8
  • 21
  • Sometimes its just because of old plugin cache. Try `flutter clean` and rebuild you app. Hopefully it will work fine – Hamza Jun 04 '21 at 09:28
  • tried a lot but nothin works, app close then again run as same android studio did, but nothing changed – Adnan haider Jun 04 '21 at 09:37
  • I used same plugin in one of my apps and it was working fine. Try the code here might help you https://github.com/m-hamzashakeel/Here-I-Am-Alert-App – Hamza Jun 04 '21 at 09:53
  • @Hamza you add this plugin but not use anywhere i see no location permission anything else. – Adnan haider Jun 04 '21 at 10:05
  • 1
    the locations will be on button press and same goes for permission. The file will be homeScreen or something like that – Hamza Jun 04 '21 at 11:11
  • This solution worked for me: [enter link description here](https://stackoverflow.com/a/74781329/9805273) – AzeTech Dec 13 '22 at 07:31

5 Answers5

3

Running flutter clean and flutter pub get fixed the issue for me. I uninstalled the application, cleared the cache of my device and rebuilt the app. This time there was a popup asking to give location permission to the app.

I gave the access and got the current position of the device (latitude and longitude).

Also make sure you upgrade flutter to 3.0.0 by running flutter upgrade

3

Maybe someone will need my solution. This happens because GeolocatorPlatform.instance is not initialized. Call _registerPlatformInstance() where you need.

import 'package:geolocator_android/geolocator_android.dart';
import 'package:geolocator_apple/geolocator_apple.dart';

void _registerPlatformInstance() {
    if (Platform.isAndroid) {
      GeolocatorAndroid.registerWith();
    } else if (Platform.isIOS) {
      GeolocatorApple.registerWith();
    }
}
3

Stop running the app completely and restart the app. make sure that the app is killed before restart click stop button, refer below,

enter image description here

AzeTech
  • 623
  • 11
  • 21
1

If you just installed the package (geolocator), just restart the app or even better the phone.

Gedeon Mutshipayi
  • 2,871
  • 3
  • 21
  • 42
0

Upgrade your flutter Run on terminal flutter upgrade or flutter upgrade —-force Then =>flutter pub outdated Then =>flutter pub upgrade After that =>flutter pub upgrade —-major-versions

Finally go to

yourProjectName/android/app/build.gradle

Change:

android {
   compileSdkVersion ##
…
…
}

To:

android {
   compileSdkVersion 33
…
…
}