google-maps - 如何在颤动中更改谷歌地图 API 的“我的位置”按钮位置?
问题描述
我正在使用波纹管小部件,我想将 MyLocation 按钮更改到我的地图视图中的底部位置
GoogleMap(
onMapCreated: onMapCreated,
options: GoogleMapOptions(
myLocationEnabled :true,
mapType: MapType.hybrid,
cameraPosition: CameraPosition(
target: LatLng(6.8814635,79.8876697),
zoom: 15.0,),
),
),
解决方案
我找到了解决方案。我创建 FAB 按钮来更改我的位置按钮
GoogleMap(
mapType: MapType.hybrid,
initialCameraPosition: _kGooglePlex,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
myLocationEnabled: true,
),
floatingActionButton: FloatingActionButton.extended(
onPressed: _currentLocation,
label: Text('My Location'),
icon: Icon(Icons.location_on),
),
);
}
另外,设置_currentLocation
调用我的位置的方法
void _currentLocation() async {
final GoogleMapController controller = await _controller.future;
LocationData currentLocation;
var location = new Location();
try {
currentLocation = await location.getLocation();
} on Exception {
currentLocation = null;
}
controller.animateCamera(CameraUpdate.newCameraPosition(
CameraPosition(
bearing: 0,
target: LatLng(currentLocation.latitude, currentLocation.longitude),
zoom: 17.0,
),
));
}
推荐阅读
- javascript - Update all the users specific property with http trigger
- json - 如何停止 JSON 响应打印 NIL?- 斯威夫特
- sql-server - 在 SQL 联合中为一个表提供 Case 语句
- sql - postgresql:尝试创建表时关系“table_name”不存在
- ios - 带有桥头的 obj-c 未调用 Swift 代码
- django - Django admin 忽略动态生成的表单字段
- python - 如何从 docx 文件中提取数据?
- php - 使用“简单的 html 解析器”提取表数据
- javascript - 如何将这个改变不透明度的 SVG onclick 属性放入 VS2017
- regex - 如何将特定路径上文件的文件扩展名与正则表达式匹配?