【问题标题】:How to draw polyline on google map in flutter如何在颤动的谷歌地图上绘制折线
【发布时间】:2019-10-03 12:50:40
【问题描述】:

我正在尝试使用颤振谷歌地图库在两个位置之间绘制折线。


// here the  Map Body

          body:Container(
        child: GoogleMap(
          myLocationEnabled: true,
          mapType: MapType.hybrid,
          onMapCreated: (GoogleMapController controller){
            mapController=controller;
          }, 
          initialCameraPosition: CameraPosition(
           target: center,
           zoom: 11.0 
         ),
         markers:  markers,
        ),
      ),

【问题讨论】:

    标签: google-maps dart flutter google-polyline


    【解决方案1】:

    在 Google() 小部件中使用 polygons 并尝试这样

            GoogleMap(
                        markers: markersAr,
                        myLocationEnabled: true,
                        initialCameraPosition: CameraPosition(
                          target: LatLng(6.843369, 79.874814),
    
                          zoom: 12.99,
                        ),
                        polygons: Set<Polygon>.of(<Polygon>[
                          Polygon(
                              polygonId: PolygonId('area'),
                              points: getPoints(),
                              geodesic: true,
                              strokeColor: Colors.red.withOpacity(0.6),
                              strokeWidth: 5,
                              fillColor: Colors.redAccent.withOpacity(0.1),
                              visible: true),
    
    
                        ]),)
    

    把你的坐标放进去

    getPoint()

    getPoints() {
        return [
          LatLng(6.862472, 79.859482),
          LatLng(6.862258, 79.862325),
          LatLng(6.863121, 79.863644),
          LatLng(6.864538, 79.865039),
          LatLng(6.865124, 79.864546),
          LatLng(6.866451, 79.864667),
          LatLng(6.867303, 79.86544),
          LatLng(6.867899, 79.865826),
          LatLng(6.867867, 79.866727),
          LatLng(6.864884, 79.870333),
          LatLng(6.861859, 79.873112),
          LatLng(6.861593, 79.87499),
          LatLng(6.860837, 79.876427),
    
        ];
      }
    

    【讨论】:

      【解决方案2】:

      我假设您已经找到了解决方案,但以防万一其他人发现自己在这里......

      你会这样做。

      List<Polyline> _polyLine = [];
      
      _polyLine.add(Polyline(
              polylineId: PolylineId("route1"),
              color: Colors.blue,
              patterns: [
                PatternItem.dash(20.0),
                PatternItem.gap(10)
              ],
              width: 3,
              points: [
                LOCATION_A,
                LOCATION_B,
              ],
            ));
      .
      .
      .
      .
      
      GoogleMap(
                myLocationEnabled: true,
                mapType: MapType.hybrid,
                onMapCreated: (GoogleMapController controller){
                  mapController=controller;
                }, 
                initialCameraPosition: CameraPosition(
                 target: center,
                 zoom: 11.0 
               ),
               markers:  markers,
               polylines: _polyLine.toSet(),
      ),
      
      

      【讨论】:

        【解决方案3】:

        如果您使用的是 goole_maps_flutter 插件,则在 0.5.6 版中,GoogleMaps 已添加对折线的支持。 https://pub.dev/packages/google_maps_flutter#056

        您可以像添加标记一样添加它:

        body:Container(
            child: GoogleMap(
              myLocationEnabled: true,
              mapType: MapType.hybrid,
              onMapCreated: (GoogleMapController controller){
                mapController=controller;
              }, 
              initialCameraPosition: CameraPosition(
               target: center,
               zoom: 11.0 
             ),
             markers:  markers,
             polylines: polylines, // Set<Polyline>
            ),
          ),
        

        查看以下示例:

        https://github.com/flutter/plugins/blob/master/packages/google_maps_flutter/example/lib/place_polyline.dart

        【讨论】:

          猜你喜欢
          • 2017-03-09
          • 2019-12-16
          • 1970-01-01
          • 1970-01-01
          • 2015-10-17
          • 1970-01-01
          • 2016-05-14
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多