diff --git a/lib/src/mapbox_map.dart b/lib/src/mapbox_map.dart index 1a765a848..fc2c8f9e7 100644 --- a/lib/src/mapbox_map.dart +++ b/lib/src/mapbox_map.dart @@ -114,7 +114,8 @@ class MapboxMap extends StatefulWidget { /// when the map tries to turn on the My Location layer. final bool myLocationEnabled; - /// The mode used to let the map's camera follow the device's physical location + /// The mode used to let the map's camera follow the device's physical location. + /// `myLocationEnabled` needs to be true for values other than `MyLocationTrackingMode.None` to work. final MyLocationTrackingMode myLocationTrackingMode; /// The mode to render the user location symbol diff --git a/mapbox_gl_web/lib/src/convert.dart b/mapbox_gl_web/lib/src/convert.dart index 376cdb1a0..838d850e7 100644 --- a/mapbox_gl_web/lib/src/convert.dart +++ b/mapbox_gl_web/lib/src/convert.dart @@ -45,6 +45,7 @@ class Convert { sink.setMyLocationEnabled(options['myLocationEnabled']); } if (options.containsKey('myLocationTrackingMode')) { + //Should not be invoked before sink.setMyLocationEnabled() sink.setMyLocationTrackingMode(options['myLocationTrackingMode']); } if (options.containsKey('myLocationRenderMode')) { diff --git a/mapbox_gl_web/lib/src/mapbox_map_controller.dart b/mapbox_gl_web/lib/src/mapbox_map_controller.dart index 7f970fcac..f1a090d30 100644 --- a/mapbox_gl_web/lib/src/mapbox_map_controller.dart +++ b/mapbox_gl_web/lib/src/mapbox_map_controller.dart @@ -542,6 +542,10 @@ class MapboxMapController extends MapboxGlPlatform @override void setMyLocationTrackingMode(int myLocationTrackingMode) { + if(_geolocateControl==null){ + //myLocationEnabled is false, ignore myLocationTrackingMode + return; + } if (myLocationTrackingMode == 0) { _addGeolocateControl(trackUserLocation: false); } else {