Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static Object toJson(String markerId) {
return data;
}

private static Object toJson(LatLng latLng) {
static Object toJson(LatLng latLng) {
return Arrays.asList(latLng.latitude, latLng.longitude);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Marker;
import io.flutter.plugin.common.MethodCall;
Expand All @@ -49,6 +50,7 @@ final class GoogleMapController
GoogleMapOptionsSink,
MethodChannel.MethodCallHandler,
OnMapReadyCallback,
GoogleMap.OnMapClickListener,
PlatformView {

private static final String TAG = "GoogleMapController";
Expand Down Expand Up @@ -154,6 +156,7 @@ public void onMapReady(GoogleMap googleMap) {
googleMap.setOnCameraMoveListener(this);
googleMap.setOnCameraIdleListener(this);
googleMap.setOnMarkerClickListener(this);
googleMap.setOnMapClickListener(this);
updateMyLocationEnabled();
markersController.setGoogleMap(googleMap);
updateInitialMarkers();
Expand Down Expand Up @@ -212,6 +215,13 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
}
}

@Override
public void onMapClick(LatLng latLng) {
final Map<String, Object> arguments = new HashMap<>(2);
arguments.put("position", Convert.toJson(latLng));
methodChannel.invokeMethod("map#onTap", arguments);
}

@Override
public void onCameraMoveStarted(int reason) {
final Map<String, Object> arguments = new HashMap<>(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma mark - Conversion of JSON-like values sent via platform channels. Forward declarations.

static NSDictionary* PositionToJson(GMSCameraPosition* position);
static NSArray* LocationToJson(CLLocationCoordinate2D position);
static GMSCameraPosition* ToOptionalCameraPosition(NSDictionary* json);
static GMSCoordinateBounds* ToOptionalBounds(NSArray* json);
static GMSCameraUpdate* ToCameraUpdate(NSArray* data);
Expand Down Expand Up @@ -242,6 +243,10 @@ - (void)mapView:(GMSMapView*)mapView didTapInfoWindowOfMarker:(GMSMarker*)marker
[_markersController onInfoWindowTap:markerId];
}

- (void)mapView:(GMSMapView*)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
[_channel invokeMethod:@"map#onTap" arguments:@{@"position" : LocationToJson(coordinate)}];
}

@end

#pragma mark - Implementations of JSON conversion functions.
Expand Down
3 changes: 3 additions & 0 deletions packages/google_maps_flutter/lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class GoogleMapController {
case 'infoWindow#onTap':
_googleMapState.onInfoWindowTap(call.arguments['markerId']);
break;
case 'map#onTap':
_googleMapState.onTap(LatLng._fromJson(call.arguments['position']));
break;
default:
throw MissingPluginException();
}
Expand Down
9 changes: 9 additions & 0 deletions packages/google_maps_flutter/lib/src/google_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class GoogleMap extends StatefulWidget {
this.onCameraMoveStarted,
this.onCameraMove,
this.onCameraIdle,
this.onTap,
}) : assert(initialCameraPosition != null),
super(key: key);

Expand Down Expand Up @@ -91,6 +92,9 @@ class GoogleMap extends StatefulWidget {
/// animations and the user has stopped interacting with the map.
final VoidCallback onCameraIdle;

/// Called every time a [GoogleMap] is tapped.
final ArgumentCallback<LatLng> onTap;

/// True if a "My Location" layer should be shown on the map.
///
/// This layer includes a location indicator at the current device location,
Expand Down Expand Up @@ -223,6 +227,11 @@ class _GoogleMapState extends State<GoogleMap> {
final MarkerId markerId = MarkerId(markerIdParam);
_markers[markerId].infoWindow.onTap();
}

void onTap(LatLng position) {
assert(position != null);
widget.onTap(position);
}
}

/// Configuration options for the GoogleMaps user interface.
Expand Down