Skip to content

[google_maps_flutter] Strange issue when adding marker with some delay in IOS #169005

Open
@Mohit8G

Description

@Mohit8G

Steps to reproduce

Add large amount of marker on map and everything falls apart.

google_maps_flutter: ^2.10.0

Expected results

The markers should be plotted on given lat lng.

Actual results

the marker is plotted on given lat lng but also some random marker is added on map in case of ios

Code sample

Code sample
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

class GoogleMapIosIssue extends StatefulWidget {
  const GoogleMapIosIssue({super.key});

  @override
  State<GoogleMapIosIssue> createState() => _GoogleMapIosIssueState();
}

class _GoogleMapIosIssueState extends State<GoogleMapIosIssue> {
  Set<Marker> markers = {};
  late GoogleMapController _googleMapController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GoogleMap(
        initialCameraPosition: const CameraPosition(
          target: LatLng(20.5937, 78.9629),
          zoom: 4,
        ),
        markers: markers,
        onMapCreated: onMapCreated,
      ),
    );
  }

  void onMapCreated(controller) {
    _googleMapController = controller;
    createItineraries();
    _generateMarkers(1000);
    setState(() {});
  }

  Future<void> createItineraries() async {
    final double minLat = 14.925;
    final double maxLat = 15.825;
    final double minLng = 73.675;
    final double maxLng = 74.215;

    final random = Random();

    for (int i = 0; i < 100; i++) {
      await Future.delayed(const Duration(milliseconds: 10));
      double lat = minLat + random.nextDouble() * (maxLat - minLat);
      double lng = minLng + random.nextDouble() * (maxLng - minLng);

      markers.add(
        Marker(markerId: MarkerId('marker11_$i'), position: LatLng(lat, lng), icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueYellow)),
      );
    }

    setState(() {});
  }


  final double minLat = 8.0;
  final double maxLat = 37.0;
  final double minLng = 68.0;
  final double maxLng = 97.0;

  void _generateMarkers(int count) {
    final random = Random();

    for (int i = 0; i < count; i++) {
      double lat = minLat + random.nextDouble() * (maxLat - minLat);
      double lng = minLng + random.nextDouble() * (maxLng - minLng);

      markers.add(
        Marker(
          markerId: MarkerId('marker_$i'),
          position: LatLng(lat, lng),
          icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueMagenta),
        ),
      );
    }

    setState(() {});
  }
}

Screenshots or Video

Screenshots / Video demonstration We can see that in android marker are in one place but in ios marker are placed randomly on map Image Image

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.3 23D56 darwin-arm64, locale en-IN)
    • Flutter version 3.22.2 on channel stable at /Users/mohit/.puro/envs/new/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (12 months ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/mohit/Library/Android/sdk
    • Platform android-35, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • 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.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • 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.9+0-17.0.9b1087.7-11185874)

[✓] IntelliJ IDEA Ultimate Edition (version 2024.3.4.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • 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

[✓] Connected device (5 available)
    • sdk gphone64 arm64 (mobile)     • emulator-5554                        • android-arm64  • Android 15 (API 35) (emulator)
    • iPhone 15 Plus (mobile)         • 5B28CAA6-3AFA-4B69-9623-373D19D9B1AE • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 14.3 23D56 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 14.3 23D56 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 136.0.7103.114
    ! Error: Browsing on the local area network for iPhone - QA. Ensure the device is unlocked and attached with a cable or associated with the same local area network as
      this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for Office - iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network
      as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: qualityA truly polished experiencefound in release: 3.29Found to occur in 3.29found in release: 3.33Found to occur in 3.33has 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 specificallyteam-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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy