Fix google map marker in center

后端 未结 5 1673
情歌与酒
情歌与酒 2020-12-28 09:41

In my flutter app. I am using google_maps_plugin . The link is https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter . I want to fix the m

5条回答
  •  無奈伤痛
    2020-12-28 10:26

    This is based on the @Joe answer but it has more accurated pin position and no other class is required:

    double mapWidth = MediaQuery.of(context).size.width;
    double mapHeight = MediaQuery.of(context).size.height - 215;
    double iconSize = 40.0;
    
    return new Stack(
        alignment: Alignment(0.0, 0.0),
        children: [
          new Container(
            width: mapWidth,
            height: mapHeight,
            child: _googleMap
          ),
          new Positioned(
            top: (mapHeight - iconSize)/ 2,
            right: (mapWidth - iconSize)/ 2,
            child: new Icon(Icons.person_pin_circle, size: iconSize),
          )
      ]);
    

    This solution don't require to repaint the entire Screen (no setState call) when user update the position. You won't see that weird marker "movement".

提交回复
热议问题