Repository: flutter
Issue: [google_map_flutter] IOS - Implementing custom movement and zooming unusable movement gesture
Labels: platform-ios,p: maps,package,has reproducible steps,P2,team-ios,triaged-ios,found in release: 3.24

### Steps to reproduce

Wrap the Google map widget with a gesture detector and implement custom onScaleUpdate, and onScaleEnd methods to handle movements. The script works fine on Android devices and IOS emulators, but it failed on IOS devices (iPhone 12, 15 with the latest IOS). The need for custom implementation is that the client wanted an overlay pin that is always centered on the map, when using the default behavior the zoom gesture will zoom in way makes the center shifted as the user zoom in or out.

### Expected results

The scroll movement should be close to the one offered by the package

### Actual results

On IOS the camera movement is not functioning as expected
 

### Code sample

<details open><summary>Code sample</summary>

```dart
class LocationSelectionPage extends StatefulWidget {
  const LocationSelectionPage({super.key,});

  @override
  State<LocationSelectionPage> createState() => _LocationSelectionPageState();
}
class _LocationSelectionPageState extends State<LocationSelectionPage> {
  final ValueNotifier<LatLng?> _selectedLatLng = ValueNotifier(null);
  final ValueNotifier<bool> _isScrolling = ValueNotifier(false);
  final ValueNotifier<bool> _isZooming = ValueNotifier(false);
  final LatLng _defaultLatLng = const LatLng(33.2712896, 35.1964972);
  GoogleMapController? _mapController;
  late CameraPosition _initialCameraPosition;
  double _currentZoomLevel = 15.0;
  double _lastReportedScale = 1.0;

  @override
  void initState() {
    super.initState();
    _initialCameraPosition = CameraPosition(
      target: _selectedLatLng.value != null
          ? _selectedLatLng.value!
          : _defaultLatLng,
      zoom: _currentZoomLevel,
    );
  }
  
  Widget build(BuildContext context) {
                   return GestureDetector(
                            onScaleUpdate: _onScaleUpdate,
                            onScaleEnd: _onScrollEnd,
                            child: GoogleMap(
                              initialCameraPosition: _initialCameraPosition,
                              // onTap: _onMapTap,
                              // myLocationEnabled: true,
                              myLocationButtonEnabled: false,
                              onMapCreated: (GoogleMapController controller) {
                                _mapController = controller;
                              },
                              zoomControlsEnabled: false,
                              scrollGesturesEnabled: false,
                              zoomGesturesEnabled: false,
                            ),
                          );
       }
  

  void _onScaleUpdate(ScaleUpdateDetails details) {
    if (details.pointerCount == 2 && !_isZooming.value) {
      _isZooming.value = true; // Start zooming when two pointers are detected
      _lastReportedScale = details.scale; // Initialize the last reported scale
    }

    if (_isZooming.value) {
      // Calculate the zoom change based on the difference from the initial scale
      double zoomChange = (details.scale / _lastReportedScale - 1) *
          10; // Adjust sensitivity here

      // Apply a controlled zoom change
      double newZoomLevel = _currentZoomLevel +
          zoomChange * 0.1; // Multiply by 0.1 to ensure small steps
      if (newZoomLevel >= 0) {
        _mapController?.moveCamera(CameraUpdate.zoomTo(newZoomLevel));
        _currentZoomLevel = newZoomLevel;
      }

      // Update the scale only after applying changes
      _lastReportedScale = details.scale;
    } else if (details.scale == 1.0 && _isZooming.value) {
      // End the zoom operation
      _isZooming.value = false;
      _lastReportedScale = 1.0; // Reset scale to neutral when zoom ends
    }

    // Handle map dragging if not zooming
    if (!_isZooming.value) {
      _isScrolling.value = true;
      if (Platform.isIOS) {
        _mapController?.moveCamera(
          CameraUpdate.scrollBy(
            -details.focalPointDelta.dx,
            -details.focalPointDelta.dy,
          ),
        );
      } else {
        _mapController?.moveCamera(
          CameraUpdate.scrollBy(
            -details.focalPointDelta.dx,
            -details.focalPointDelta.dy,
          ),
        );
      }
    }
  }

  void _onScrollEnd(ScaleEndDetails details) {
    // Reset scroll/zoom values
    _lastReportedScale = 1.0;
    _isScrolling.value = false;
    _isZooming.value = false;
    // Set the location to the center of the screen
    _getScreenLatLng(
      MediaQuery.of(context).size.center(Offset.zero),
    )?.then((latLng) => _selectedLatLng.value = latLng);
  }
 }
  
class LocationCustomPin extends StatelessWidget {
  const LocationCustomPin({
    super.key,
    this.pinColor = const Color(0xFFD11149),
  });

  final Color pinColor;

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Assets.images.svg.location.svg(
          width: 56,
          height: 56,
          colorFilter: ColorFilter.mode(
            pinColor,
            BlendMode.srcIn,
          ),
        ),
        Container(
          height: 8,
          width: 8,
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            color: pinColor,
          ),
        ),
      ],
    );
  }
}
  ```

</details>


### Screenshots or Video

<details open>
<summary>The camera keeps returning to the middle</summary>

https://github.com/user-attachments/assets/59323ff2-db39-4912-b59b-a86010dbff43
</details>


### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.24.0, on macOS 14.5 23F79 darwin-arm64, locale en-LB)
    • Flutter version 3.24.0 on channel stable at /Users/yazan/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 80c2e84975 (2 weeks ago), 2024-07-30 23:06:49 +0700
    • Engine revision b8800d88be
    • Dart version 3.5.0
    • DevTools version 2.37.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc4)
    • Android SDK at /Users/yazan/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0-rc4
    • ANDROID_HOME = /Users/yazan/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)

[✓] VS Code (version 1.92.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (5 available)
    • SM A736B (mobile)               • ***                          • android-arm64  • Android 14 (API 34)
    • iPhone 15 Pro Max (mobile)      • *** • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 14.5 23F79 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 14.5 23F79 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 127.0.6533.119

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>