Нарисуйте маршрут во Flutter с пакетом google_maps_flutter - PullRequest
0 голосов
/ 20 сентября 2019

У меня уже есть карта с google_maps_flutter, и у меня есть 2 маркера.Я хотел бы провести маршрут между ними.Кто-нибудь может мне помочь?

Когда я использую тот, который предложен @ CopsOnRoad , у меня отображается изображение.Я хотел бы, чтобы маршрут был синей линией, которая идет лучшим путем вперед.

Figure that demonstrates the problem

1 Ответ

2 голосов
/ 20 сентября 2019

Поскольку вы не поделились ни одним кодом, я приведу пример из здесь

Добавьте это к вашему StatefulWidget подклассу.

Map<PolylineId, Polyline> _mapPolylines = {};
int _polylineIdCounter = 1;

void _add() {
  final String polylineIdVal = 'polyline_id_$_polylineIdCounter';
  _polylineIdCounter++;
  final PolylineId polylineId = PolylineId(polylineIdVal);

  final Polyline polyline = Polyline(
    polylineId: polylineId,
    consumeTapEvents: true,
    color: Colors.red,
    width: 5,
    points: _createPoints(),
  );

  setState(() {
    _mapPolylines[polylineId] = polyline;
  });
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text("Maps"),
      actions: <Widget>[IconButton(icon: Icon(Icons.add), onPressed: _add)],
    ),
    body: GoogleMap(
      initialCameraPosition: const CameraPosition(target: LatLng(0, 0), zoom: 4.0),
      polylines: Set<Polyline>.of(_mapPolylines.values),
    ),
  );
}

List<LatLng> _createPoints() {
  final List<LatLng> points = <LatLng>[];
  points.add(LatLng(1.875249, 0.845140));
  points.add(LatLng(4.851221, 1.715736));
  points.add(LatLng(8.196142, 2.094979));
  points.add(LatLng(12.196142, 3.094979));
  points.add(LatLng(16.196142, 4.094979));
  points.add(LatLng(20.196142, 5.094979));
  return points;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...