Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[google_maps_flutter_web] The google maps widget doesn't behave as the mobile version (polyline) #86349

Closed
MarkAlexanderDev opened this issue Jul 13, 2021 · 12 comments
Assignees
Labels
assigned for triage issue is assigned to a domain expert for further triage found in release: 2.2 Found to occur in 2.2 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: maps Google Maps plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-web Web applications specifically r: invalid Issue is closed as not valid

Comments

@MarkAlexanderDev
Copy link

I'm currently working on a Flutter application mobile/web and I have an issue with the "google_maps_flutter" package. My goal is to display a map with a course drawn thanks to a polyline.

Here is a screenshot of the Android version which is working as expected :

Screenshot_20210713_153909_dev doarun app

Now, we have the web version which displays the Polyline as a straight line heading to the north :

image

Here is the code sample of my GoogleMap widget :

GoogleMap(
                  gestureRecognizers: Set()
                    ..add(Factory<PanGestureRecognizer>(
                        () => PanGestureRecognizer())),
                  initialCameraPosition: CameraPosition(
                      target: polylines.first.points.first, zoom: 20.0),
                  mapType: MapType.hybrid,
                  polylines: polylines,
                  compassEnabled: false,
                  tiltGesturesEnabled: false),
            ),
[✓] Flutter (Channel stable, 2.2.3, on Linux, locale en_US.UTF-8)
    • Flutter version 2.2.3 at /home/Mark/snap/flutter/common/flutter
    • Framework revision f4abaa0735 (12 days ago), 2021-07-01 12:46:11 -0700
    • Engine revision 241c87ad80
    • Dart version 2.13.4

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /home/Mark/Android/Sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /var/lib/snapd/snap/android-studio/113/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+0-b944-P17168821)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
    • cmake version 3.10.2
    • ninja version 1.8.2
    • pkg-config version 0.29.1

[✓] Android Studio (version 4.2)
    • Android Studio at /var/lib/snapd/snap/android-studio/113/android-studio
    • Flutter plugin version 58.0.1
    • Dart plugin version 202.8531
    • Java version OpenJDK Runtime Environment (build 11.0.8+0-b944-P17168821)

[✓] Connected device (3 available)
    • MAR LX1A (mobile) • L2N0219A30008750 • android-arm64  • Android 10 (API 29)
    • Linux (desktop)   • linux            • linux-x64      • Linux
    • Chrome (web)      • chrome           • web-javascript • Google Chrome 91.0.4472.77

• No issues found!

Thank you in advance for your time 🙏

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Jul 14, 2021
@darshankawar
Copy link
Member

@MarkAlexanderDev
Try using this plugin and see if it helps, https://pub.dev/packages/flutter_polyline_points

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 14, 2021
@MarkAlexanderDev
Copy link
Author

I've just tried and I get the same result :(

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 14, 2021
@darshankawar
Copy link
Member

@MarkAlexanderDev
Can you provide a complete minimal code sample ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 14, 2021
@MarkAlexanderDev
Copy link
Author

Sure, thank you for your help

class LatestRun extends StatelessWidget {
  final EntityGroup group;

  final PolylinePoints polylinePoints = PolylinePoints();
  final Set<Polyline> polylines = {};

  LatestRun({@required this.group});

  @override
  Widget build(BuildContext context) {
    final PolylineId id = PolylineId("poly");
    polylines.add(Polyline(
        width: 3,
        color: mainColor,
        polylineId: id,
        points: convertToLatLng(
            polylinePoints.decodePolyline(group.lastRunPolyline))));
    return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
      Container(
        width: 150,
        color: mainColor,
        padding: EdgeInsets.all(8.0),
        child: Text("Latest runs".toUpperCase(), style: textStyleTitle),
      ),
      Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              group.lastRunner +
                  " put in " +
                  (group.lastRunDistance / 1000).toStringAsFixed(3) +
                  "km",
              style: textStyleH2.copyWith(color: mainColor),
            ),
            SizedBox(height: 5),
            SizedBox(
              width: kIsWeb ? 500 : MediaQuery.of(context).size.width,
              height: kIsWeb ? 500 : MediaQuery.of(context).size.width,
              child: GoogleMap(
                  gestureRecognizers: Set()
                    ..add(Factory<PanGestureRecognizer>(
                        () => PanGestureRecognizer())),
                  initialCameraPosition: CameraPosition(
                      target: _getAverageLatLng(polylines.first.points),
                      zoom: 15.0),
                  mapType: MapType.terrain,
                  polylines: polylines,
                  compassEnabled: false,
                  tiltGesturesEnabled: false),
            ),
          ],
        ),
      )
    ]);
  }

  LatLng _getAverageLatLng(List<LatLng> points) {
    final List<double> lats = [];
    points.forEach((element) {
      lats.add(element.latitude);
    });
    final List<double> lons = [];
    points.forEach((element) {
      lons.add(element.longitude);
    });
    return LatLng(lats.reduce((a, b) => a + b) / lats.length,
        lons.reduce((a, b) => a + b) / lons.length);
  }
}
List<LatLng> convertToLatLng(List<PointLatLng> points) {
  List<LatLng> result = <LatLng>[];
  for (int i = 0; i < points.length; i++)
    result.add(LatLng(points[i].latitude, points[i].longitude));
  return result;
}

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 14, 2021
@darshankawar
Copy link
Member

I came up with a complete code sample based on your code above, but getting compile error on EntityGroup, not sure what that is:

code sample

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

void main() {
  runApp(MaterialApp(
    home: LatestRun(),
  ));
}

class LatestRun extends StatelessWidget {
  final EntityGroup group;

  final PolylinePoints polylinePoints = PolylinePoints();
  final Set<Polyline> polylines = {};

  LatestRun({@required this.group});

  @override
  Widget build(BuildContext context) {
    final PolylineId id = PolylineId("poly");
    polylines.add(Polyline(
        width: 3,
        color: Colors.blue,
        polylineId: id,
        points: convertToLatLng(
            polylinePoints.decodePolyline(group.lastRunPolyline))));
    return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
      Container(
        width: 150,
        color: Colors.blue,
        padding: EdgeInsets.all(8.0),
        child: Text("Latest runs".toUpperCase()),
      ),
      Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              group.lastRunner +
                  " put in " +
                  (group.lastRunDistance / 1000).toStringAsFixed(3) +
                  "km",
              style: TextStyle(fontStyle: FontStyle.italic).copyWith(color: Colors.blue),
            ),
            SizedBox(height: 5),
            SizedBox(
              width: kIsWeb ? 500 : MediaQuery.of(context).size.width,
              height: kIsWeb ? 500 : MediaQuery.of(context).size.width,
              child: GoogleMap(
                  gestureRecognizers: Set()
                    ..add(Factory<PanGestureRecognizer>(
                            () => PanGestureRecognizer())),
                  initialCameraPosition: CameraPosition(
                      target: _getAverageLatLng(polylines.first.points),
                      zoom: 15.0),
                  mapType: MapType.terrain,
                  polylines: polylines,
                  compassEnabled: false,
                  tiltGesturesEnabled: false),
            ),
          ],
        ),
      )
    ]);
  }

  LatLng _getAverageLatLng(List<LatLng> points) {
    final List<double> lats = [];
    points.forEach((element) {
      lats.add(element.latitude);
    });
    final List<double> lons = [];
    points.forEach((element) {
      lons.add(element.longitude);
    });
    return LatLng(lats.reduce((a, b) => a + b) / lats.length,
        lons.reduce((a, b) => a + b) / lons.length);
  }

  List<LatLng> convertToLatLng(List<PointLatLng> points) {
    List<LatLng> result = <LatLng>[];
    for (int i = 0; i < points.length; i++)
      result.add(LatLng(points[i].latitude, points[i].longitude));
    return result;
  }
}




@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 15, 2021
@MarkAlexanderDev
Copy link
Author

Sorry, I forgot to provide it. It's a class I use to store data from my API:

class EntityGroup extends GetxController {
  String name = "";
  RxString icon = "👟".obs;
  double targetKm = 10.0;
  String owner = "";
  List accounts = [];

  //last run
  String lastRunPolyline = "";
  String lastRunner = "";
  int lastRunTimestamp = 0;
  double lastRunDistance = 0.0;

  EntityGroup();

  EntityGroup.fromJson(Map<String, dynamic> data, {String key = ""}) {
    fromJson(data, key: key);
  }

  Map<String, dynamic> toMap() {
    return {
      "icon": this.icon.value,
      "targetKm": this.targetKm,
      "owner": this.owner,
      "accounts": this.accounts,
      "lastRunPolyline": this.lastRunPolyline,
      "lastRunner": this.lastRunner,
      "lastRunTimestamp": this.lastRunTimestamp,
      "lastRunDistance": this.lastRunDistance,
    };
  }

  String toJson() {
    return json.encode(toMap());
  }

  bool fromJson(Map<String, dynamic> data, {String key = ""}) {
    if (data == null) return false;
    this.name = key;
    this.icon.value = data["icon"];
    this.targetKm = data["targetKm"];
    this.owner = data["owner"];
    this.accounts.assignAll(data["accounts"]);
    this.lastRunPolyline = data["lastRunPolyline"];
    this.lastRunner = data["lastRunner"];
    this.lastRunTimestamp = data["lastRunTimestamp"];
    this.lastRunDistance = data["lastRunDistance"];
    return true;
  }
}

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 15, 2021
@darshankawar
Copy link
Member

@MarkAlexanderDev
Sorry for going back and forth, but it seems you are using https://pub.dev/packages/get/example 3rd party plugin in your EntityGroup class. Please provide a self-contained code sample that we can directly use.
Thanks.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 16, 2021
@MarkAlexanderDev
Copy link
Author

Sorry for the late answer @darshankawar, I created a GitHub repository to isolate the issue. You should be able to test it easily: https://github.com/MarkAlexanderDev/google_maps_flutter_web_isuue

/!\ Don't forget to replace the API key of google maps in the AndroidManifest and in the Index.html.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 5, 2021
@darshankawar
Copy link
Member

Thanks for the repo. I see the same behavior using latest stable version on web.

  1. Mobile:

Screenshot 2021-08-06 at 11 02 32 AM

  1. Web:

Screenshot 2021-08-06 at 11 04 57 AM

flutter doctor -v
[✓] Flutter (Channel stable, 2.2.3, on Mac OS X 10.15.4 19E2269 darwin-x64,
    locale en-GB)
    • Flutter version 2.2.3 at /Users/dhs/documents/fluttersdk/flutter
    • Framework revision f4abaa0735 (5 weeks ago), 2021-07-01 12:46:11 -0700
    • Engine revision 241c87ad80
    • Dart version 2.13.4

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.10.1

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

[✓] VS Code (version 1.58.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (4 available)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 92.0.4515.107

• No issues found!



Cc: @ditman

@darshankawar darshankawar added p: first party p: maps Google Maps plugin platform-web Web applications specifically found in release: 2.2 Found to occur in 2.2 has reproducible steps The issue has been confirmed reproducible and is ready to work on and removed in triage Presently being triaged by the triage team labels Aug 6, 2021
@ditman
Copy link
Member

ditman commented Aug 7, 2021

I'm going to try and reproduce/minimize this example even further. I suspect it has to do with the polyline points not being in the correct order (and mobile sorting them before painting them), but I'm not sure entirely sure! (something similar happened with polygons and holes)

This might also be an issue with passing the polylines as a prop of the map, and not something added later through the controller, we've had a couple of issues like that in the past with other geometries.

@ditman ditman added the P2 Important issues not at the top of the work list label Aug 7, 2021
@ditman ditman self-assigned this Aug 7, 2021
@ditman ditman added this to Not Started in Flutter Web Plugins via automation Aug 7, 2021
@ditman ditman added the assigned for triage issue is assigned to a domain expert for further triage label Aug 7, 2021
@ditman
Copy link
Member

ditman commented Aug 9, 2021

This seems to be a bug in the implementation of package:flutter_polyline_points :: decodePolyline method in the web, see below:

Dammyololade/flutter_polyline_points#40 (comment)

I just applied the workaround above and got this when decoding the string:

Screen Shot 2021-08-09 at 3 24 23 PM

I'm going to close this as an issue for flutter_polyline_points, I guess they should fix it in their package!

@ditman ditman closed this as completed Aug 9, 2021
Flutter Web Plugins automation moved this from Not Started to Done Aug 9, 2021
@darshankawar darshankawar added the r: invalid Issue is closed as not valid label Aug 10, 2021
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
assigned for triage issue is assigned to a domain expert for further triage found in release: 2.2 Found to occur in 2.2 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: maps Google Maps plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-web Web applications specifically r: invalid Issue is closed as not valid
Projects
Development

No branches or pull requests

3 participants