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

get Current Location Null #248

Closed
BhaveshPrince opened this issue Apr 22, 2019 · 20 comments
Closed

get Current Location Null #248

BhaveshPrince opened this issue Apr 22, 2019 · 20 comments
Labels
platform: android Issue is related to the Android platform. status: closed (missing info) Indicates the issue was automatically closed due to a lack of information.

Comments

@BhaveshPrince
Copy link

Hello Sir,

while i run app into android platform getting location null.

Please helm me

@xuanjinliang
Copy link

xuanjinliang commented Apr 26, 2019

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

@ened
Copy link
Contributor

ened commented May 20, 2019

Try the latest develop branch, please.

@mvanbeusekom mvanbeusekom added platform: android Issue is related to the Android platform. status: needs more info We need more information before we can continue work on this issue. labels May 22, 2019
@mvanbeusekom
Copy link
Member

@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;
}

@ronaldG19
Copy link

ronaldG19 commented Jun 7, 2019

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

@FalkF
Copy link

FalkF commented Jun 9, 2019

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): E/flutter (29584): #2 Geolocator.getCurrentPosition (package:geolocator/geolocator.dart:96:32) E/flutter (29584): E/flutter (29584): #3 MapPageState.createVendingLocation (package:eismann/pages/mapPage.dart:71:44) E/flutter (29584): 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): 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. (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. (dart:async/zone.dart:947:23) E/flutter (29584): #23 Timer._createTimer. (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:

{\"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.

@Xgamefactory
Copy link

thanks @FalkF !
upgrading gradle solved the issue.

@trey-rosius
Copy link

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

@moboer
Copy link

moboer commented Aug 27, 2019

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

@mvanbeusekom
Copy link
Member

Issues should be solved with version 6.0.0

@kostasoft
Copy link

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.

@mvanbeusekom
Copy link
Member

@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,
);

@kostasoft
Copy link

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

@FalkF
Copy link

FalkF commented Apr 28, 2021

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

@mvanbeusekom
Copy link
Member

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).

@kostasoft
Copy link

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?

@selankon
Copy link

Hi,

I have the same problem runing the example, giving permisions etc..

@Jorgee97
Copy link

Same issue here. can we reopen this issue? because It has not been resolved yet.

Thanks in advance

@xainnn
Copy link

xainnn commented Jan 25, 2022

same issue current location not get...plz help

@xainnn
Copy link

xainnn commented Jan 25, 2022

@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,
);

not working sir

@xcplus
Copy link

xcplus commented Sep 21, 2022

I have the same problem runing the example; Google Play Store is missing

@mvanbeusekom mvanbeusekom added status: closed (missing info) Indicates the issue was automatically closed due to a lack of information. and removed status: needs more info We need more information before we can continue work on this issue. labels Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: android Issue is related to the Android platform. status: closed (missing info) Indicates the issue was automatically closed due to a lack of information.
Projects
None yet
Development

No branches or pull requests