-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[google_maps_flutter_android] Add advanced markers support #10381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[google_maps_flutter_android] Add advanced markers support #10381
Conversation
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.
Code Review
This pull request introduces support for Advanced Markers in the Android implementation of google_maps_flutter. The changes are comprehensive, including dependency updates, new logic for handling AdvancedMarkerOptions like PinConfig and collisionBehavior, and the addition of AdvancedMarkerClusterRenderer for clustering. A new API, isAdvancedMarkersAvailable, is also included. The example app has been updated with new pages to demonstrate these features. The implementation is solid and well-tested. I have a couple of minor suggestions to improve code quality and maintainability.
...r_android/android/src/main/java/io/flutter/plugins/googlemaps/ClusterManagersController.java
Outdated
Show resolved
Hide resolved
...google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java
Show resolved
Hide resolved
44e6b7a to
3cfb6f4
Compare
reidbaker
left a comment
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.
Java code reviewed. Sorry this took so long but thank you so much for your contribution.
| */ | ||
| private void initializeRenderer(ClusterManager<MarkerBuilder> clusterManager) { | ||
| final ClusterRenderer<MarkerBuilder> clusterRenderer = | ||
| markerType == PlatformMarkerType.ADVANCED_MARKER |
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.
Nit: Can you make this a switch instead of a turnary for readability?
| getPinConfigFromPlatformPinConfig( | ||
| pinConfigBitmap, assetManager, density, bitmapDescriptorFactory); | ||
| return bitmapDescriptorFactory.fromPinConfig(pinConfig); | ||
| } catch (Exception e) { |
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.
Can you pick a more specific set of exceptions here?
| ? toInt(pinConfigBitmap.getBackgroundColor()) | ||
| : null; | ||
| final Integer borderColor = | ||
| pinConfigBitmap.getBorderColor() != null ? toInt(pinConfigBitmap.getBorderColor()) : null; |
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.
There is a lot of null handling in this code. Each line is easy enough to understand but i think it would be more readable if you made helper methods.
| return JointType.DEFAULT; | ||
| } | ||
|
|
||
| static int collisionBehaviorFromPigeon( |
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.
Can you add a javadoc for this method?
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.
Added
| if (googleMap == null) { | ||
| throw new FlutterError( | ||
| "GoogleMap uninitialized", | ||
| "getMapCapabilities() called prior to map initialization", |
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.
Should this say isAdvancedMarkersAvailable somewhere in the error?
| this.markerOptions = new MarkerOptions(); | ||
| MarkerBuilder(String markerId, String clusterManagerId, PlatformMarkerType markerType) { | ||
| this.markerOptions = | ||
| markerType == PlatformMarkerType.ADVANCED_MARKER |
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.
Same here can you make this a switch instead of a turnary?
|
|
||
| @Override | ||
| public void setCollisionBehavior(@AdvancedMarkerOptions.CollisionBehavior int collisionBehavior) { | ||
| if (markerOptions.getClass() == AdvancedMarkerOptions.class) { |
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.
Can you write this to not use getClass? In general we dont like having to use getClass or instanceOf they are are code smells.
...droid/android/src/test/java/io/flutter/plugins/googlemaps/ClusterManagersControllerTest.java
Outdated
Show resolved
Hide resolved
| .setIcon(icon) | ||
| .setInfoWindow(infoWindow); | ||
| .setInfoWindow(infoWindow) | ||
| .setCollisionBehavior(PlatformMarkerCollisionBehavior.REQUIRED_DISPLAY); |
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.
Do you have a test for the behavior if someone passes an invalid version? if not can you add one
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.
I don't think It's possible to pass an invalid value nor test it here.
304d11c to
4e3e0e9
Compare
4e3e0e9 to
82fa871
Compare
This PR adds Advanced markers support to the Android implementation of google_maps_flutter.
Approved combined PR: #7882
Approved and merged platform interface PR: #9737
Issue: flutter/flutter#155526
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3