Skip to content

[google_maps_flutter] Add Advanced Markers support #7882

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

Open
wants to merge 136 commits into
base: main
Choose a base branch
from

Conversation

aednlaxer
Copy link
Contributor

@aednlaxer aednlaxer commented Oct 16, 2024

This PR adds Advanced Markers support to google_maps_flutter as discussed in #155526. The document from the issue offers several options to implement Advanced Markers support, this PR uses option 1 (Advanced Marker Dart class is a subclass Marker class).

Summary of changes:

  • Add map capability check
  • Add AdvancedMarker class
  • Add MarkerCollisionBehavior enum to control Advanced Marker's behavior when it collides with another marker
  • Add PinConfig bitmap descriptor for customizing Advanced Marker's pin and icon
  • Add markerType parameter to indicate that Advanced Markers should be used
  • Rename cloudMapId to mapId

Notes:

  • native implementations need to know what kind of marker should be used, this is needed to use correct marker options, cluster manager and marker controller. Indicating marker type is done by using a markerType option when creating a GoogleMap (could be marker or advancedMarker). Default option is marker
  • cloudMapId is deprecated in favor of mapId. New name follows SDKs, documentation and Cloud Console naming.
  • web implementation uses generics because gmaps.Marker and gmaps.AdvancedMarkerElement are not related to each other and should be handled differently
  • legacy markers are deprecated but still supported in Maps Javascript API. google_maps_flutter still uses them by default in this PR because of backward-compatibility. #130472 is related, package users will be able to use Advanced Markers to fix the deprecation warning
  • Advanced Markers example on iOS doesn't show advanced markers, seems to be a known issue
  • Using Flutter widget as Advanced Marker icon (so called View Marker) is not part of this PR, this was discussed in the document and later removed as we agreed that it should be a separate issue

Resolves #155526

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link
Contributor

@reidbaker reidbaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High level android code review. I am concerned by having to runtime type check class.

That said thank you for opening this pull request.

@stuartmorgan-g stuartmorgan-g added the triage-ios Should be looked at in iOS triage label Nov 21, 2024
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only looked at the app-facing and platform interface packages so far, but there are some fundamental structure questions at the interface layer.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

App-facing and platform interface look good, so once the platform reviews are in this can be split apart.

@ash2moon ash2moon requested a review from reidbaker April 29, 2025 18:35
@aednlaxer
Copy link
Contributor Author

@reidbaker @vashworth could you please give this another round of review? All comments should be resolved now

@aednlaxer aednlaxer requested a review from vashworth May 19, 2025 12:16
@aednlaxer
Copy link
Contributor Author

Linux_web web_platform_tests_wasm_shard_3 master is failing because innerHtml returns a different object type on Flutter main:

  • Flutter stable: String?
  • Flutter main: JSAny

@ditman is this something that should be type-checked in tests or is there a better way to deal with it?

@reidbaker reidbaker requested review from camsim99 and removed request for reidbaker May 19, 2025 18:10
@ditman
Copy link
Member

ditman commented May 19, 2025

@aednlaxer this has to do with (possible) differences in implementation of those types in JS vs WASM (the failing tests are WASM ones, it seems).

Have you tried compiling your demo app with --wasm and seeing if it actually fails, or is it a problem with the tests? If we're using dart:html in tests that's a problem-ish, we should move away from that and use package:web and dart:js_interop instead.

I can't take a look right now, but will try to figure out a patch later this week.

(PS: I suspect this needs a strategic .toDart/.toJS in the failing assertion, when the type is JSAny? probably/maybe :))

style: config.style,
);
}

PlatformMarkerType? _platformMarkerTypeFromMarkerType(MarkerType? markerType) {
Copy link
Contributor

@vashworth vashworth May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github won't let me add a comment on the line, but collisionBehavior needs to be added to _platformMarkerFromMarker function above. Currently collisionBehavior is always being set to null. There should also probably be a test that should have caught this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, thanks! I've added a test for updateMarkers that works with AdvancedMarkers and a check for collisionBehavior there. Do you think it's worth adding a test just for _platformMarkerTypeFromMarkerType?

Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the Android implementation looks good to me! Left some questions regarding testing.

Comment on lines +202 to +207
final String backgroundColorKey = "backgroundColor";
final String borderColorKey = "borderColor";
final String glyphTextKey = "glyphText";
final String glyphTextColorKey = "glyphTextColor";
final String glyphColorKey = "glyphColor";
final String glyphBitmapDescriptorKey = "glyphBitmapDescriptor";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these used?

@@ -327,6 +328,20 @@ public void GetBitmapFromBytesThrowsErrorIfInvalidImageData() {
fail("Expected an IllegalArgumentException to be thrown");
}

@Test
public void GetBitmapFromPinConfig() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this test be modified to ensure that PinConfigs are created as expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for isAdvancedMarkersAvailable?

@@ -115,6 +120,13 @@ public void setZIndex(float zIndex) {
markerOptions.zIndex(zIndex);
}

@Override
public void setCollisionBehavior(@AdvancedMarkerOptions.CollisionBehavior int collisionBehavior) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be nice to add setCollisionBehavior tests for the two implementation in this PR.

@@ -1949,6 +2040,33 @@ void googleMapsTests() {
// https://github.com/flutter/flutter/issues/131071
skip: true,
);

testWidgets('markerWithPinConfig', (WidgetTester tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this testing anything? Can we remove it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: google_maps_flutter platform-android platform-ios platform-web triage-android Should be looked at in Android triage triage-ios Should be looked at in iOS triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Advanced Marker support to google_maps_flutter
8 participants