Flutter-geolocator: get Current Location Null

Created on 22 Apr 2019  ·  15Comments  ·  Source: Baseflow/flutter-geolocator

Hello Sir,

while i run app into android platform getting location null.

Please helm me

android needs more info

All 15 comments

Me Too.

My Code:

Geolocator geolocator = Geolocator();
Future<Position> getLocation() async {
    Position currentLocation;

    GeolocationStatus permission = await geolocator.checkGeolocationPermissionStatus();
    print('location-->${permission}');

    try {
      currentLocation = await geolocator.getCurrentPosition(
          desiredAccuracy: LocationAccuracy.best);
    } on PlatformException catch (e) {
      print('e-->${e}');
      currentLocation = null;
    }

    print('currentLocation-->${currentLocation}');

    return currentLocation;
  }

Output:
I/flutter (25071): location-->GeolocationStatus.granted
W/GooglePlayServicesUtil(25071): Google Play Store is missing.

My phone is not installed Google Play Store and Google Play Service

Try the latest develop branch, please.

@BhaveshPrince, @xuanjinliang, does this issue still occur with the latest version (5.0.0) of the Geolocator plugin?

@xuanjinliang, if you don't have Google Play Store you can try forcing (although this should be done automatically) the plugin to use the legacy LocationManager to acquire the location by setting the forceAndroidLocationManager property of the Geolocator class to true:

try {
  final Geolocator geolocator = Geolocator()
    ..forceAndroidLocationManager = true;
  position = await geolocator.getLastKnownPosition(
    desiredAccuracy: LocationAccuracy.best);
} on PlatformException {
  position = null;
}

@mvanbeusekom used to work perfectly but got an error earlier. Just hangs without returning back any results.

Had the same behaviour with 4.0.3 (nothing happens after the getCurrentPosition invocation).
With 5.0.1I get following platform exception:

expand

W/GooglePlayServicesUtil(29584): Google Play Store is missing.
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584): Failed to handle method call
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584): java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at com.baseflow.geolocator.data.LocationOptions.parseArguments(LocationOptions.java:17)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at com.baseflow.geolocator.tasks.TaskFactory.createCurrentLocationTask(TaskFactory.java:36)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at com.baseflow.geolocator.GeolocatorPlugin.onMethodCall(GeolocatorPlugin.java:66)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:88)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:219)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at android.app.ActivityThread.main(ActivityThread.java:6718)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#flutter.baseflow.com/geolocator/methods(29584):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/flutter (29584): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, java.lang.String cannot be cast to java.util.Map, null)
E/flutter (29584): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter (29584): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302:33)
E/flutter (29584): <asynchronous suspension>
E/flutter (29584): #2      Geolocator.getCurrentPosition (package:geolocator/geolocator.dart:96:32)
E/flutter (29584): <asynchronous suspension>
E/flutter (29584): #3      MapPageState.createVendingLocation (package:eismann/pages/mapPage.dart:71:44)
E/flutter (29584): <asynchronous suspension>
E/flutter (29584): #4      MapGestureMixin.handleTap (package:flutter_map/src/gestures/gestures.dart:94:13)
E/flutter (29584): #5      _TapPositionDetectorState._postCallback (package:positioned_tap_detector/positioned_tap_detector.dart:108:15)
E/flutter (29584): <asynchronous suspension>
E/flutter (29584): #6      _TapPositionDetectorState._onTimeout (package:positioned_tap_detector/positioned_tap_detector.dart:52:7)
E/flutter (29584): #7      _invokeErrorHandler (dart:async/async_error.dart:17:29)
E/flutter (29584): #8      _HandleErrorStream._handleError (dart:async/stream_pipe.dart:286:9)
E/flutter (29584): #9      _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:168:13)
E/flutter (29584): #10     _rootRunBinary (dart:async/zone.dart:1144:38)
E/flutter (29584): #11     _CustomZone.runBinary (dart:async/zone.dart:1037:19)
E/flutter (29584): #12     _CustomZone.runBinaryGuarded (dart:async/zone.dart:939:7)
E/flutter (29584): #13     _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:355:15)
E/flutter (29584): #14     _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:373:16)
E/flutter (29584): #15     _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:272:7)
E/flutter (29584): #16     _SyncStreamController._sendError (dart:async/stream_controller.dart:768:19)
E/flutter (29584): #17     _StreamController._addError (dart:async/stream_controller.dart:648:7)
E/flutter (29584): #18     _StreamController.addError (dart:async/stream_controller.dart:600:5)
E/flutter (29584): #19     Stream.timeout.onListen.<anonymous closure> (dart:async/stream.dart:1512:22)
E/flutter (29584): #20     _rootRun (dart:async/zone.dart:1124:13)
E/flutter (29584): #21     _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (29584): #22     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
E/flutter (29584): #23     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:21:15)
E/flutter (29584): #24     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
E/flutter (29584): #25     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
E/flutter (29584): #26     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:171:12)
locationOptions: ```dart {\"accuracy\":\"high\",\"distanceFilter\":0,\"forceAndroidLocationManager\":true,\"timeInterval\":0} ```

Update:

Got it working after I upgraded com.android.tools.build:gradle:3.3.1'to 3.4.1 (as used in the example) in the android build.gradle. Had to change distribution in gradle-wrapper.properties to https\://services.gradle.org/distributions/gradle-5.1.1-all.zip. I also used flutter clean and deleted the app from my phone. I don't know what the fix was in the end but maybe this helps.

thanks @FalkF !
upgrading gradle solved the issue.

Commenting out this line
..forceAndroidLocationManager = true
Solved the issue for me

@xuanjinliang ,me too,If you solve this problem, I hope you can tell me.

Issues should be solved with version 6.0.0

geolocator: ^7.0.3
In my phone is not installed Google Play Store and Google Play Service
Geoposition is not defined, in the logs:
W/GooglePlayServicesUtil(26708): <packagename> requires the Google Play Store, but it is missing.

forceAndroidLocationManager - does not find such a method in class Geolocator.

@kostasoft Since version 6.0.0 the forceAndroidLocationManager method has been replaced by a parameter on the getCurrentPosition and getPositionStream methods.

Meaning from version 6.0.0 you can force the use of the LocationManager SDK like this:

Position position = await Geolocator.getCurrentPosition(
  desiredAccuracy: LocationAccuracy.high,
  forceAndroidLocationManager: true,
);

Thank you. I did as you said, still an error:
... requires the Google Play Store, but it is missing.

Just a sanity check, you used forceAndroidLocationManager: true, or false? False should be correct ;)

Just a sanity check, you used forceAndroidLocationManager: true, or false? False should be correct ;)

This is incorrect, false is the default behavior and doesn't force the use of the legacy Android Location Manager.

In this case the phone doesn't support Google Play Services and therefore is unable to use the FusedLocationProviderClient and you'd want to switch to use of the LocationManager (this should be handled in the Geolocator internally, but some users like to force this manually which can be done using the forceAndroidLocationManager parameter).

In any case, the plugin requires the Google Play Store (in the logs) and the location is not detected.
Is there a solution to this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lqmminh picture lqmminh  ·  6Comments

Sammius picture Sammius  ·  4Comments

joesnarky picture joesnarky  ·  3Comments

BigWillieStyle picture BigWillieStyle  ·  6Comments

fawadkhanucp picture fawadkhanucp  ·  3Comments