-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[google_maps_flutter_web] Add "My Location" Widget #6868
Conversation
small demo demo-2.mov |
9ad030b
to
6668606
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments, sorting in degree of importance (IMO):
- Use the
watchPosition
API so MyLocation automatically updates (instead ofgetCurrentPosition
). - Handle the case where users deny Geolocation permissions to the app, so the app doesn't crash or freeze
await
ing for a Future/Stream that will never complete. - Do not "hard-code" the translucent blue halo in the
blue-dot.png
, because that needs to be computed from thecoords.accuracy
value that the Geolocation API returns. Blue dot should be a blue circle with a white border and nothing more. - Speaking of assets: make the mylocation-sprite-2x.png part of the assets of the package, and do not download it from a gstatic URL.
- Move (most of) the code to a separate
src/my_location.dart
file to not bloat the MapsController code, and also to make it easier to test. Pass parameters for the things that you need (like thegmaps.GMap
or theMarkersController
) - Try to make the "loading" animation (and the "done" state) come from CSS, rather than using JS to build those animations (I provided a jsfiddle example).
- Some comments around naming that are completely subjective, but try to make the name of the method describe what's happening inside of it (for example, currently:
_moveToCurrentLocation
is a little bit weird)
Thanks for the contribution, very exciting to see this land!
packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md
Outdated
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml
Outdated
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_web/example/web/index.html
Outdated
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart
Outdated
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart
Outdated
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart
Outdated
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart
Outdated
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart
Outdated
Show resolved
Hide resolved
// Get current location | ||
Future<LatLng> _getCurrentLocation() async { | ||
final Geoposition location = | ||
await window.navigator.geolocation.getCurrentPosition(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method will not update the user's location if they move around, unless something else on the map changes. I think this should use the watchPosition
API, that returns a Stream<Geoposition>
and then respond to the events from that stream. Some changes to this PR:
- If the user wants to render the MyLocation dot: subscribe to the
watchPosition
Stream, and on eachGeolocation
event update the Marker.- The
first
event of thewatchPosition
Stream can be used to remove the "waiting" animation class from the button, for example, and to get ready the marker that needs to be rendered.
- The
- If the user wants to stop rendering their location, it's easy to remove whatever subscription to the Stream that we do, and whatever cleanup is needed.
Some documentation:
- See: https://api.dart.dev/stable/2.18.6/dart-html/Geolocation/watchPosition.html
- Async in Dart - Streams: https://dart.dev/tutorials/language/streams
Update from triage: this in on @ditman's radar, but there's been high-priority work in another plugin that has taken precedence. |
@stuartmorgan Thank you for letting me know. |
We've just completed the migration of the plugin code to the flutter/packages repository, as described in https://flutter.dev/go/flutter-plugins-repo-migration, and this repository is now being archived. Unfortunately that means that all in-progress PRs here must be moved to flutter/packages. Please see our instructions for an explanation of how to move your PR, and if you have any issues moving your PR please don't hesitate to reach out in the #hackers-ecosystem channel in Discord. Our apologies that your PR was caught in this one-time transition. We're aware that it's disruptive in the short term, and appreciate your help in getting us to a better long-term state! |
Currently, we don't "My Location" widget, so this PR i want support that feature, Thanks
Issue: flutter/flutter#64073
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.