tlserver / flutter_map_location_marker

A flutter map plugin for displaying device current location.
https://pub.dev/packages/flutter_map_location_marker
BSD 3-Clause "New" or "Revised" License
97 stars 81 forks source link

Map is not centering #37

Closed davideroffo closed 1 year ago

davideroffo commented 1 year ago

I'm using this package as referenced in the simple guide: https://pub.dev/packages/flutter_map_location_marker#usage

But the map once starts up, is not centered in the user marker.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FlutterMap(
        mapController: mapController,
        options: MapOptions(
          zoom: 7,
        ),
        children: [
          TileLayerWidget(
            options: TileLayerOptions(
              minZoom: 1,
              maxZoom: 18,
              backgroundColor: Colors.black,
              urlTemplate: 'http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
              subdomains: ['mt0', 'mt1', 'mt2', 'mt3'],
            ),
          ),
          PolygonLayerWidget(
            options: PolygonLayerOptions(
              polygonCulling: false,
              polygons: [
                Polygon(
                  points: [
                    LatLng(currentPosition.latitude + 1,
                        currentPosition.longitude + 1),
                    LatLng(currentPosition.latitude + 4,
                        currentPosition.longitude + 4),
                    LatLng(currentPosition.latitude + 3,
                        currentPosition.longitude + 3),
                  ],
                  color: Colors.blue.withOpacity(0.5),
                ),
              ],
            ),
          ),
          LocationMarkerLayerWidget(),
        ],
      ),
    );
  }

am I missing something?

tlserver commented 1 year ago

This is the default behaviour. You need to change the centerOnLocationUpdate in LocationMarkerPlugin to once or always yourself.

LocationMarkerLayerWidget(
  plugin: LocationMarkerPlugin(
    centerOnLocationUpdate: CenterOnLocationUpdate.once,
  ),
),

See document and this example if you need a FAB button for centering.

PS. This issue page in github is for reporting bugs or requesting new feature. If you have 'how to use' question, better ask in Stackover Flow or in the flutter map Discord channel.