Skip to content

[google_maps_flutter_web] Map pins don't move #83467

Closed
flutter/packages
#3697
@SittiphanSittisak

Description

@SittiphanSittisak

Hi, a pin in Google Maps doesn't move after setState a new location on the web(It move on mobile).

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.2.0, on Microsoft Windows [Version 10.0.19042.985], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.56.0)
[√] Connected device (3 available)

• No issues found!

You can repeat by using this code(Try in mobile and web(I am using firebase host) to see this bug).

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.3
  google_maps_flutter: ^2.0.6
  google_maps_flutter_web: ^0.3.0

minimal code sample page1.dart:
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

class Page1 extends StatefulWidget {
  @override
  _Page1State createState() => _Page1State();
}

class _Page1State extends State<Page1> {
  @override
  void initState() {
    Timer time = Timer.periodic(Duration(seconds: 3), (Timer t) => timer());
    super.initState();
  }

  LatLng _kMapCenter1 = LatLng(19.0182, 72.8479);
  LatLng _kMapCenter2 = LatLng(19.0183, 72.8480);
  bool toggle = false;

  Future timer() async {
    if (toggle) {
      setState(() {
        _kMapCenter1 = LatLng(19.0181, 72.8478);
        _kMapCenter2 = LatLng(19.0184, 72.8481);
      });
      toggle = !toggle;
    } else {
      setState(() {
        _kMapCenter1 = LatLng(19.0182, 72.8479);
        _kMapCenter2 = LatLng(19.0183, 72.8480);
      });
      toggle = !toggle;
    }

    print(_kMapCenter1.longitude);
  }

  Completer<GoogleMapController> _controller = Completer();

  static final CameraPosition _kGooglePlex = CameraPosition(
    target: LatLng(37.42796133580664, -122.085749655962),
    zoom: 14.4746,
  );

  static final CameraPosition _kLake = CameraPosition(
      bearing: 192.8334901395799,
      target: LatLng(19.01825595, 72.84793854),
      tilt: 59.440717697143555,
      zoom: 19.151926040649414);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: GoogleMap(
        markers: Set<Marker>.of(_createMarker()),
        mapType: MapType.hybrid,
        initialCameraPosition: _kGooglePlex,
        onMapCreated: (GoogleMapController controller) {
          _controller.complete(controller);
        },
      ),
      floatingActionButton: FloatingActionButton.extended(
        onPressed: _goToTheLake,
        label: Text('To the lake!'),
        icon: Icon(Icons.directions_boat),
      ),
    );
  }

  //ทำ marker
  Set<Marker> _createMarker() {
    print(5555);
    return {
      Marker(
          markerId: MarkerId("marker_1"),
          position: _kMapCenter1,
          infoWindow: InfoWindow(title: 'Marker 1'),
          rotation: 90),
      Marker(
        markerId: MarkerId("marker_2"),
        position: _kMapCenter2,
      ),
    };
  }

  Future<void> _goToTheLake() async {
    final GoogleMapController controller = await _controller.future;
    controller.animateCamera(CameraUpdate.newCameraPosition(_kLake));
  }
}

main.dart:

import 'package:flutter/material.dart';
import 'package:flutter_project/page1.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: Page1(),
    );
  }
}

Thank guy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 2.2Found to occur in 2.2has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: mapsGoogle Maps pluginpackageflutter/packages repository. See also p: labels.platform-webWeb applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions