Skip to content

Commit 336fb13

Browse files
committed
[google_maps_flutter] Add onPointOfInterestTap callback
Expose a place-ID-only POI tap stream across the federated plugin stack (Android, iOS, web) so apps can react when users tap built-in map POIs. Fixes flutter/flutter#60695
1 parent 13b49f4 commit 336fb13

85 files changed

Lines changed: 1262 additions & 89 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.18.0
2+
3+
* Adds support for tapping points of interest on the map.
4+
15
## 2.17.1
26

37
* Updates README to link to implementation packages for platform-specific

‎packages/google_maps_flutter/google_maps_flutter/example/lib/map_click.dart‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class _MapClickBodyState extends State<_MapClickBody> {
3535
GoogleMapController? mapController;
3636
LatLng? _lastTap;
3737
LatLng? _lastLongPress;
38+
String? _lastPointOfInterestPlaceId;
3839

3940
@override
4041
Widget build(BuildContext context) {
@@ -51,6 +52,11 @@ class _MapClickBodyState extends State<_MapClickBody> {
5152
_lastLongPress = pos;
5253
});
5354
},
55+
onPointOfInterestTap: (PointOfInterestId pointOfInterestId) {
56+
setState(() {
57+
_lastPointOfInterestPlaceId = pointOfInterestId.value;
58+
});
59+
},
5460
);
5561

5662
final columnChildren = <Widget>[
@@ -73,6 +79,17 @@ class _MapClickBodyState extends State<_MapClickBody> {
7379
child: Text(_lastLongPress != null ? 'Long pressed' : '', textAlign: TextAlign.center),
7480
),
7581
);
82+
final lastPointOfInterestTap =
83+
'Point of interest place ID:\n${_lastPointOfInterestPlaceId ?? ""}\n';
84+
columnChildren.add(Center(child: Text(lastPointOfInterestTap, textAlign: TextAlign.center)));
85+
columnChildren.add(
86+
Center(
87+
child: Text(
88+
_lastPointOfInterestPlaceId != null ? 'Point of interest tapped' : '',
89+
textAlign: TextAlign.center,
90+
),
91+
),
92+
);
7693
}
7794
return Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: columnChildren);
7895
}

‎packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
5454
MinMaxZoomPreference,
5555
PatternItem,
5656
PinConfig,
57+
PointOfInterestId,
5758
Polygon,
5859
PolygonId,
5960
Polyline,

‎packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class GoogleMapController {
5959
.listen((_) => _googleMapState.widget.onCameraIdle!()),
6060
);
6161
}
62+
_streamSubscriptions.add(
63+
GoogleMapsFlutterPlatform.instance
64+
.onPointOfInterestTap(mapId: mapId)
65+
.listen((PointOfInterestTapEvent e) => _googleMapState.onPointOfInterestTap(e.value)),
66+
);
6267
_streamSubscriptions.add(
6368
GoogleMapsFlutterPlatform.instance
6469
.onMarkerTap(mapId: mapId)

‎packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class GoogleMap extends StatefulWidget {
133133
this.onCameraIdle,
134134
this.onTap,
135135
this.onLongPress,
136+
this.onPointOfInterestTap,
136137
this.markerType = GoogleMapMarkerType.marker,
137138
this.colorScheme,
138139
String? mapId,
@@ -297,6 +298,11 @@ class GoogleMap extends StatefulWidget {
297298
/// Called every time a [GoogleMap] is long pressed.
298299
final ArgumentCallback<LatLng>? onLongPress;
299300

301+
/// Called when a point of interest on the map is tapped.
302+
///
303+
/// May not be supported on all platforms.
304+
final ArgumentCallback<PointOfInterestId>? onPointOfInterestTap;
305+
300306
/// True if a "My Location" layer should be shown on the map.
301307
///
302308
/// This layer includes a location indicator at the current device location,
@@ -685,6 +691,13 @@ class _GoogleMapState extends State<GoogleMap> {
685691
}
686692
}
687693

694+
void onPointOfInterestTap(PointOfInterestId pointOfInterestId) {
695+
final ArgumentCallback<PointOfInterestId>? onPointOfInterestTap = widget.onPointOfInterestTap;
696+
if (onPointOfInterestTap != null) {
697+
onPointOfInterestTap(pointOfInterestId);
698+
}
699+
}
700+
688701
void onTap(LatLng position) {
689702
final ArgumentCallback<LatLng>? onTap = widget.onTap;
690703
if (onTap != null) {

‎packages/google_maps_flutter/google_maps_flutter/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_maps_flutter
22
description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
5-
version: 2.17.1
5+
version: 2.18.0
66

77
environment:
88
sdk: ^3.10.0

‎packages/google_maps_flutter/google_maps_flutter/test/fake_google_maps_flutter_platform.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ class FakeGoogleMapsFlutterPlatform extends GoogleMapsFlutterPlatform {
227227
return mapEventStreamController.stream.whereType<CircleTapEvent>();
228228
}
229229

230+
@override
231+
Stream<PointOfInterestTapEvent> onPointOfInterestTap({required int mapId}) {
232+
return mapEventStreamController.stream.whereType<PointOfInterestTapEvent>();
233+
}
234+
230235
@override
231236
Stream<MapTapEvent> onTap({required int mapId}) {
232237
return mapEventStreamController.stream.whereType<MapTapEvent>();

‎packages/google_maps_flutter/google_maps_flutter/test/google_maps_flutter_export_test.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void main() {
5050
main_file.MinMaxZoomPreference;
5151
main_file.PatternItem;
5252
main_file.PinConfig;
53+
main_file.PointOfInterestId;
5354
main_file.Polygon;
5455
main_file.PolygonId;
5556
main_file.Polyline;

‎packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.20.0
2+
3+
* Adds support for tapping points of interest on the map.
4+
15
## 2.19.12
26

37
* Bumps the androidx group across 10 directories with 1 update.

‎packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.google.android.gms.maps.model.MapCapabilities;
3939
import com.google.android.gms.maps.model.MapStyleOptions;
4040
import com.google.android.gms.maps.model.Marker;
41+
import com.google.android.gms.maps.model.PointOfInterest;
4142
import com.google.android.gms.maps.model.Polygon;
4243
import com.google.android.gms.maps.model.Polyline;
4344
import com.google.android.gms.maps.model.TileOverlay;
@@ -385,6 +386,14 @@ public void onCircleClick(Circle circle) {
385386
circlesController.onCircleTap(circle.getId());
386387
}
387388

389+
@Override
390+
public void onPoiClick(PointOfInterest pointOfInterest) {
391+
if (pointOfInterest.placeId != null) {
392+
flutterApi.onPointOfInterestTap(
393+
pointOfInterest.placeId, (Result<Unit> result) -> Unit.INSTANCE);
394+
}
395+
}
396+
388397
@Override
389398
public void onGroundOverlayClick(@NonNull GroundOverlay groundOverlay) {
390399
groundOverlaysController.onGroundOverlayTap(groundOverlay.getId());
@@ -421,6 +430,7 @@ private void setGoogleMapListener(@Nullable GoogleMapListener listener) {
421430
googleMap.setOnPolygonClickListener(listener);
422431
googleMap.setOnPolylineClickListener(listener);
423432
googleMap.setOnCircleClickListener(listener);
433+
googleMap.setOnPoiClickListener(listener);
424434
googleMap.setOnMapClickListener(listener);
425435
googleMap.setOnMapLongClickListener(listener);
426436
googleMap.setOnGroundOverlayClickListener(listener);

0 commit comments

Comments
 (0)