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 Web throws type error on adding polyline #65189

Closed
SirLink opened this issue Sep 3, 2020 · 4 comments
Closed

Google Maps Web throws type error on adding polyline #65189

SirLink opened this issue Sep 3, 2020 · 4 comments

Comments

@SirLink
Copy link

SirLink commented Sep 3, 2020

Adding a Polyline to the map throws a type error
errors.dart:163 Uncaught (in promise) Error: Expected a value of type 'List<LatLng>', but got one of type 'List<dynamic>'

The problem seems to be in this code on Convert.dart line 321
points: rawPolyline['points'] ?.map((rawPoint) => LatLng.fromJson(rawPoint)) ?.toList(),

I managed to fix it by adding a type to the map and i can now see the polyline painted on the map, though it has a default color and i can't seem to be able to change it

points: rawPolyline['points'] ?.map<LatLng>((rawPoint) => LatLng.fromJson(rawPoint)) ?.toList(),

@darshankawar
Copy link
Member

Hi @SirLink,
Please provide flutter doctor -v, a minimal complete reproducible code sample along with pubspec.yaml that shows the issue.
Thanks.

@darshankawar darshankawar added in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels Sep 4, 2020
@SirLink
Copy link
Author

SirLink commented Sep 4, 2020

Hello @darshankawar , sure
You need to run this on the web

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:quartet/quartet.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,
        // This makes the visual density adapt to the platform that you run
        // the app on. For desktop platforms, the controls will be smaller and
        // closer together (more dense) than on mobile platforms.
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  List<Polyline> polylines = List();

  @override
  void initState() {
    List<LatLng> result = decodePolyline("wezu@vcgdNf@CG_BGwACGE?GAGI?IMQYQaAS");
    final PolylineId polylineId = PolylineId("1");
    final Polyline polyline = Polyline(
      polylineId: polylineId,
      consumeTapEvents: true,
      color: Colors.blue,
      width: 5,
      points: result,
    );
    polylines.add(polyline);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          // Here we take the value from the MyHomePage object that was created by
          // the App.build method, and use it to set our appbar title.
          title: Text(widget.title),
        ),
        body: GoogleMap(
            polylines: polylines.toSet(),
            initialCameraPosition:
                CameraPosition(target: LatLng(8.98668, -79.50412),zoom: 18)));
  }
}

List<LatLng> decodePolyline(String encoded){
  List<LatLng> poly = [];
  int index = 0, len = encoded.length;
  int lat = 0, lng = 0;


  while (index < len) {
    int b, shift = 0, result = 0;
    do {
      b = codePointAt(encoded, index++) - 63;
      result |= (b & 0x1f) << shift;
      shift += 5;
    } while (b >= 0x20);
    int dlat = ((result & 1) != 0 ? -(result >> 1) : (result >> 1));
    lat += dlat;

    shift = 0;
    result = 0;
    do {
      b = codePointAt(encoded, index++) - 63;
      result |= (b & 0x1f) << shift;
      shift += 5;

    } while (b >= 0x20);

    int dlng = ((result & 1) != 0 ? -(result >> 1) : (result >> 1));

    lng += dlng;

    LatLng p =
    new LatLng((lat / 1E5).toDouble(), (lng / 1E5).toDouble());
    poly.add(p);
  }
  return poly;
}
[√] Flutter (Channel beta, 1.21.0-9.2.pre, on Microsoft Windows [Versión 10.0.19041.450], locale es-PE)
    • Flutter version 1.21.0-9.2.pre at C:\src\flutter
    • Framework revision 81a45ec2e5 (8 days ago), 2020-08-27 14:14:33 -0700
    • Engine revision 20a9531835
    • Dart version 2.10.0 (build 2.10.0-7.3.beta)


[√] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at C:\Users\wilme\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 48.1.2
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.48.2)
    • VS Code at C:\Users\wilme\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.14.0

[√] Connected device (3 available)
    • Web Server (web) • web-server • web-javascript • Flutter Tools
    • Chrome (web)     • chrome     • web-javascript • Google Chrome 85.0.4183.83
    • Edge (web)       • edge       • web-javascript • Microsoft Edge 85.0.564.44

• No issues found!

@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 Sep 4, 2020
@darshankawar
Copy link
Member

H @SirLink,
There's similar open issue related to adding polyline, 65152.
Please follow-up there for updates and any questions.
Closing this as duplicate. If you disagree, write in comments and I'll reopen.
Thanks.

@darshankawar darshankawar removed the in triage Presently being triaged by the triage team label Sep 7, 2020
@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 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants