如何在扑扑的谷歌地图上绘制折线

时间:2019-05-16 09:26:29

标签: google-maps dart flutter google-polyline

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


//Google 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,
        ),
      ),

3 个答案:

答案 0 :(得分:0)

如果您使用的是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

答案 1 :(得分:0)

我认为您已经找到了解决方案,但是以防万一有人在这里发现自己...

这就是你要怎么做。

res <- 
  df_join %>% 
  select(id = id.x, date = date.x, min.x, min.y) %>% 
  group_by(id, date) %>% 
  summarise(min = first(min.x), totmin = sum(min.y))
res
#> # A tibble: 7 x 4
#> # Groups:   id [2]
#>      id date         min totmin
#>   <dbl> <date>     <dbl>  <dbl>
#> 1     1 2015-07-18    25     25
#> 2     1 2015-07-22    15     40
#> 3     1 2015-07-23    10     50
#> 4     1 2015-07-30    15     25
#> 5     2 2015-07-10    10     10
#> 6     2 2015-07-16    20     30
#> 7     2 2015-07-23    10     30

答案 2 :(得分:0)

在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),

    ];
  }