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 140 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.

@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 :))

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.

@@ -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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't explicitly check anything with expect(), it's similar to other marker tests (markerWithLegacyBytes, markerWithAssetMapBitmapCreate etc) which are "run it to make sure it doesn't throw an exception or fail in a different way" kind of tests

Copy link
Contributor

@vashworth vashworth left a comment

Choose a reason for hiding this comment

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

iOS side LGTM

@bridgein

This comment was marked as off-topic.

@gmackall gmackall requested a review from camsim99 July 15, 2025 21:15
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.

Android LGTM!

@stuartmorgan-g stuartmorgan-g removed triage-ios Should be looked at in iOS triage triage-android Should be looked at in Android triage labels Jul 16, 2025
@stuartmorgan-g
Copy link
Contributor

@aednlaxer This has high-level LGs for all components now, so please feel free to split out the platform interface PR. I'll re-review that piece here in the meantime, but any comments can be addressed in the sub-PR.

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 re-reviewed the platform interface portion, and everything looks good there :)

auto-submit bot pushed a commit that referenced this pull request Aug 7, 2025
…#9737)

This PR adds Advanced markers support to the platform interface of `google_maps_flutter`.
Approved combined PR: #7882
Issue: [#155526](flutter/flutter#155526)

## Pre-Review Checklist

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot 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.

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Advanced Marker support to google_maps_flutter
9 participants