flutter - 如何使用 GoogleMapController 更改 MapType?
问题描述
我想用 GoogleMapController 改变 MapType。我使用 floatingActionButtom 来改变它。GoolgeMapOptions 已从 GoogleMap 小部件中删除,我无法使用此属性。现在我不知道改用什么代码。我想通过 onMapType 函数更改 Maptype(从普通到卫星),但我不能在新版本的 GoogleMap 中使用 updateMapOptions 和 GoolgeMapOptions。
class MapScreen extends StatefulWidget{
@override
State<StatefulWidget> createState() => new MapScreenState();
}
class MapScreenState extends State<MapScreen>{
GoogleMapController mapController;
MapType currentMaptype=MapType.normal;
final myGoogleMap=GlobalKey();
void _onMapController(GoogleMapController controller){
mapController=controller;
}
void _onMaptype(){
if(currentMaptype==MapType.normal){
mapController.updateMapOptions(
GoogleMapOptions(mapType: MapType.satellite);
currentMaptype=MapType.satellite;
}
else{
mapController.updateMapOptions(
GoogleMapOptions(mapType: MapType.normal);
currentMaptype=MapType.normal;
}
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
body: new Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
new GoogleMap(
initialCameraPosition:CameraPosition(
target: LatLng(85.254, 74.542)) ,
onMapCreated:_onMapController,
mapType: currentMaptype,
),
new Align(
alignment: Alignment.bottomLeft,
child: new Padding(
padding: EdgeInsets.only(bottom: 25, left: 8) ,
child: new Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
new FloatingActionButton(
onPressed: _onMaptype,
backgroundColor: Colors.green,
child: new Icon(Icons.map, color: Colors.white,size: 30),
),
],
),
),
)
],
),
);
}
}
解决方案
推荐阅读
- c# - 在 Cosmos DB 中向后分页
- python - 为什么这个数组中的所有元素,用python编程,都包含相同的字符串?
- c++ - 用 C++17 编译 Eigen 需要 _SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING 定义
- javascript - 选择所有具有精确 attr 值和值的元素,想要返回 true 或 false JQUERY
- r - 像 R 的 is.na 函数一样在 Julia 中查找缺失值
- java - 尝试在命令提示符下运行程序(找不到或加载主类)
- c - getch() 在最新版本的 Microsoft Visual Studio 2017 C 中无法正常工作
- android - 片段更改崩溃
- bash - 在脚本中执行文件时如何在bash中捕获所有输入文本和输出?
- php - 仅使用 Laravel 在其中一个表单数据中进行了一些计算后,如何显示结果?