Skip to content
This repository has been archived by the owner on Jul 11, 2021. It is now read-only.

Current location marker does not change until map is moved #10

Closed
boris612 opened this issue Nov 11, 2019 · 8 comments · Fixed by #30
Closed

Current location marker does not change until map is moved #10

boris612 opened this issue Nov 11, 2019 · 8 comments · Fixed by #30
Assignees
Labels
bug Something isn't working important A major bug

Comments

@boris612
Copy link
Contributor

When updateMapLocationOnPositionChange option is set to false, current location marker does not change to a new location (although it prints new location in console) until the map is moved.

@igaurab
Copy link
Owner

igaurab commented Nov 14, 2019

@boris612 true. I noticed that the marker will only change if the map is moving. If the map is not moving (either manually by setting updateMapLocationOnPositionChange to true) the marker will not be updated. Will look into this issue soon. Thank you.

@igaurab igaurab pinned this issue Nov 14, 2019
@igaurab igaurab self-assigned this Nov 14, 2019
@igaurab igaurab added bug Something isn't working important A major bug labels Nov 14, 2019
@konishon
Copy link
Collaborator

@igaurab I had a look into this and in user_location_layer.dart
Having the setState or removing it made no difference. If you remove the setState call.
The markers are shown and its position is updated when the map is moved (exaclty like this bug). The setState call is not re-rendering the marker.

It seems to be an active issue in with recent one being fleaflet/flutter_map#458 where the author is proposing to use keys but It did not work for me

Marker(point: LatLng(_currentLocation.latitude, _currentLocation.longitude),
            builder: (context) {
              return Stack(
                key: UniqueKey(),
                alignment: AlignmentDirectional.center,
                children: <Widget>[
                .....
                ],
              );
            })

maybe the reason being a maker is in the parent's widget tree.

@konishon
Copy link
Collaborator

konishon commented Nov 19, 2019

@igaurab It seems there are other active efforts to add user location
fleaflet/flutter_map#290

However, they have added all the location consumtion and marker movment logic in the parent widget itself, rather than a plugin.

The example flutter_map gives to move marker is to change values and call setState

We are calling setState from the plugin, maybe we could propose the issue to be looked at in their next release

@konishon
Copy link
Collaborator

@igaurab Here's a neat implementation of making markers stateful

It looks like he's subscribing to changes and then automatically call setState

 @override
  void initState() {
    mapController = MapController();
    statefulMapController = StatefulMapController(mapController: mapController);
    statefulMapController.onReady.then((_) => setState(() => ready = true));
    sub = statefulMapController.changeFeed.listen((change) => setState(() {}));
    super.initState();
  }

Also, https://github.com/synw/livemap/ which shows the users live locations, has been built on top of it.

@synw
Copy link

synw commented Nov 19, 2019

Hi guys. I wrote these packages. It's good to see guys that care about the question of rendering positions on a map. I've been working on that since a while. The question here is map assets state management. I have some ideas about that and I hope you don't mind if I sneak into your discussion to share some points of view.

The stateful map controller is able to manage all assets on map. The rendering of the map state is independant of it. As exposed below the suggested solution now is to use a stream of changes to trigger setState calls and rebuild from the controller's assets lists. The livemap packages seems to be doing exactly the same as this lib here. So maybe we can find some way to join forces instead of duplicating efforts?

I am actually thinking about rewriting the livemap package around a new state management paradigm using Provider, even thinking of dropping it in favor of another package that automatically manage all the map state (currently under heavy development): Fluxmap. I needed to update location of multiple devices on the map and needed a solution for managing frequent state updates. The paradigm is: provide a stream of location updates to the map, the rest is managed. Internaly it uses a stream provider to rebuild on state change: ex. code. The map state is accessible to the user. So basically the user just has to declare an instance of the map state, and start using the map controller or provide positions updates: all the rebuilds will be managed. These are handled via an rxdart stream internaly to debounce updates, so it can handle high toughtput of map updates.

About the stateful map controller if you want to use it be sure that it will be maintained: I use it in a lot of packages and apps. About the livemap package if I could drop it in favor of your package and help you here it would be fine. If you use the map controller feel free to share your thoughts about it and open issues with your remarks, feedback is welcome.

@synw
Copy link

synw commented Dec 17, 2019

Hi. I am currently porting my map_controller to a plugin to avoid having to listen to a stream for updates and faced the same problem. I found a way: in _subscribeToLocationChanges add this:

if (!widget.options.updateMapLocationOnPositionChange) {
    widget.map.fitBounds(widget.map.bounds, FitBoundsOptions());
}

[Edit] : this is a workaround, it does not work very well if the actions are repeated. I opened an issue in the flutter_map repo to find a viable solution

@boris612
Copy link
Contributor Author

An another (dirty) workaround could be to slightly move map and return back to the same position. For example if updateMapLocationOnPositionChange is set to false then this code could help:

var zoom = widget.options.mapController.zoom;
widget.options.mapController.move(widget.options.mapController.center,
                                  widget.options.mapController.zoom + 0.000001);
widget.options.mapController.move(widget.options.mapController.center, zoom);

@konishon
Copy link
Collaborator

@boris612 I made those exact changes and sent a PR

An another (dirty) workaround could be to slightly move map and return back to the same position. For example if updateMapLocationOnPositionChange is set to false then this code could help:

var zoom = widget.options.mapController.zoom;
widget.options.mapController.move(widget.options.mapController.center,
                                  widget.options.mapController.zoom + 0.000001);
widget.options.mapController.move(widget.options.mapController.center, zoom);

@boris612 I made those exact changes and sent a PR. I am ok with this workaround until flutter_map provides a better alternative

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working important A major bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants