我使用这个插件包google_maps_flutter
,在那里我可以打开地图,我按照每一个步骤显示地图在android和ios。但如何获得缩放值,如果我放大或缩小在谷歌地图?下面是示例飞镖代码:
class GoogleMapPage extends StatefulWidget {
const GoogleMapPage({Key? key}) : super(key: key);
@override
_GoogleMapPageState createState() => _GoogleMapPageState();
}
class _GoogleMapPageState extends State<GoogleMapPage> {
late Position userLocation;
late GoogleMapController mapController;
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
}
Future<Position> _getLocation() async {
try {
userLocation = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.best);
} catch (e) {
userLocation = null as Position;
}
return userLocation;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder(
future: _getLocation(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
return GoogleMap(
mapType: MapType.normal,
onMapCreated: _onMapCreated,
myLocationEnabled: true,
initialCameraPosition: CameraPosition(
target: LatLng(userLocation.latitude, userLocation.longitude),
zoom: 15),
);
} else {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularProgressIndicator(),
],
),
);
}
},
),
);
}
}
SOLVED我用这行代码解决了这个问题。
onCameraMove:(CameraPosition cameraPosition){
print(cameraPosition.zoom);
},