flutter-maplibre-gl icon indicating copy to clipboard operation
flutter-maplibre-gl copied to clipboard

requestMyLocationLatLng() throws Type error

Open ivanesi opened this issue 1 year ago • 2 comments

On iOS I got exception:

type 'Null' is not a subtype of type 'Map<dynamic, dynamic>'

when call controller.requestMyLocationLatLng():

#0      MethodChannelMaplibreGl.requestMyLocationLatLng (package:maplibre_gl_platform_interface/src/method_channel_maplibre_gl.dart:342:35)
<asynchronous suspension>

Future<void> onMapCreated(MaplibreMapController controller) async {
    try {
      final granted = await context.read<MapCubit>().requestLocationPermission();
      if (granted) {
        final latLng = await controller.requestMyLocationLatLng();
        _logger.trace(latLng);
      }
    } catch (e, st) {
      _logger.error(e, st);
    }
  }

On Android request freeze and no log output after it.

ivanesi avatar Jan 18 '24 12:01 ivanesi

Do you display the user's location on the map?

m0nac0 avatar Jan 18 '24 14:01 m0nac0

Seems like we should also modify https://github.com/maplibre/flutter-maplibre-gl/blob/acb428a005efd9832a0a8e7ef0945f899dfb3ca5/maplibre_gl_platform_interface/lib/src/method_channel_maplibre_gl.dart#L342 by first checking if result != null && result is Map<dynamic, dynamic> and if that is not fulfilled, return null.

m0nac0 avatar Jan 18 '24 14:01 m0nac0