Skip to content

onDragStart not firing for Markers for IOS Maps SDK #135778

@jjcazau

Description

@jjcazau

Is there an existing issue for this?

What package does this bug report belong to?

google_maps_flutter

What target platforms are you seeing this bug on?

iOS

Have you already upgraded your packages?

Yes

Dependency versions

pubspec.lock
 google_maps_flutter_ios:
    dependency: transitive
    description:
      path: "packages/google_maps_flutter/google_maps_flutter_ios"
      relative: true
    source: path
    version: "2.2.2"

Steps to reproduce

Add Google Maps Flutter.
Add marker to map and enable dragging.
All drag events except onDragStart fire.

Expected results

onDragStart should fire when long press on marker.

Actual results

onDragStart does not fire at all.

Code sample

Solution

There is a misspelling in the Google Maps IOS SDK plugin code: GoogleMapController.m - didStartDraggingMarker should be didBeginDraggingMarker according to the Google Maps IOS SDK reference.

- (void)mapView:(GMSMapView *)mapView didStartDraggingMarker:(GMSMarker *)marker {
  NSString *markerId = marker.userData[0];
  [self.markersController didStartDraggingMarkerWithIdentifier:markerId location:marker.position];
}
- (void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker {
  NSString *markerId = marker.userData[0];
  [self.markersController didStartDraggingMarkerWithIdentifier:markerId location:marker.position];
}

This fix is confirmed working on my project.

Code sample
Marker(
          markerId: MarkerId('markerItem_private_${marker.markerId}'),
          position: LatLng(marker.latitude, marker.longitude),
          icon: BitmapDescriptor.fromBytes(iconBytes),
          draggable: true,
          anchor: Offset(icon.anchorOffsetX, icon.anchorOffsetY),
          rotation: marker.rotation,
          zIndex: Zindex.marker.toDouble(),
          onDrag: (value) {
            appData.isDraggingMapMarker = true;
            debugprint('### onDrag: ${value.latitude}, ${value.longitude}');
          },
          onDragStart: (value) {
            debugprint(
                '### onDragStart: ${value.latitude}, ${value.longitude}');
            appData.isDraggingMapMarker = true;

            appData.bottomSheetController?.close();
          },
          onDragEnd: (value) {
            debugprint('### onDragEnd: ${value.latitude}, ${value.longitude}');
            appData.isDraggingMapMarker = false;
            marker.latitude = value.latitude;
            marker.longitude = value.longitude;
            marker.updateMarkerItem();
          },
          onTap: () {
            debugprint('### onTap: ${marker.latitude}, ${marker.longitude}');
            appData.bottomSheetController =
                appData.scaffoldKey.currentState?.showBottomSheet(
              elevation: 10,
              enableDrag: true,
              shape: AppTheme.shapeBorderModal,
              (context) => UiMarkerItemBottomSheet(marker: marker),
            );
          },
        );

Screenshots or Videos

No response

Logs

No response

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.13.3, on Microsoft Windows [Version 10.0.22621.2361], locale en-AU)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.0.2)
[√] Android Studio (version 2022.3)
[√] IntelliJ IDEA Ultimate Edition (version 2023.2)
[√] VS Code (version 1.82.2)
[√] Connected device (4 available)
[√] Network resources

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listfound in release: 3.13Found to occur in 3.13found in release: 3.15Found to occur in 3.15good first issueRelatively approachable for first-time contributorshas reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: mapsGoogle Maps pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions