blob: 299ac4b7cffcd2c45d598112d23124c2971b8fbb [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'page.dart';
class MoveCameraPage extends Page {
MoveCameraPage() : super(const Icon(Icons.map), 'Camera control');
@override
Widget build(BuildContext context) {
return const MoveCamera();
}
}
class MoveCamera extends StatefulWidget {
const MoveCamera();
@override
State createState() => MoveCameraState();
}
class MoveCameraState extends State<MoveCamera> {
GoogleMapController mapController;
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Center(
child: SizedBox(
width: 300.0,
height: 200.0,
child: GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition:
const CameraPosition(target: LatLng(0.0, 0.0)),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
children: <Widget>[
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.newCameraPosition(
const CameraPosition(
bearing: 270.0,
target: LatLng(51.5160895, -0.1294527),
tilt: 30.0,
zoom: 17.0,
),
),
);
},
child: const Text('newCameraPosition'),
),
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.newLatLng(
const LatLng(56.1725505, 10.1850512),
),
);
},
child: const Text('newLatLng'),
),
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.newLatLngBounds(
LatLngBounds(
southwest: const LatLng(-38.483935, 113.248673),
northeast: const LatLng(-8.982446, 153.823821),
),
10.0,
),
);
},
child: const Text('newLatLngBounds'),
),
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.newLatLngZoom(
const LatLng(37.4231613, -122.087159),
11.0,
),
);
},
child: const Text('newLatLngZoom'),
),
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.scrollBy(150.0, -225.0),
);
},
child: const Text('scrollBy'),
),
],
),
Column(
children: <Widget>[
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.zoomBy(
-0.5,
const Offset(30.0, 20.0),
),
);
},
child: const Text('zoomBy with focus'),
),
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.zoomBy(-0.5),
);
},
child: const Text('zoomBy'),
),
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.zoomIn(),
);
},
child: const Text('zoomIn'),
),
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.zoomOut(),
);
},
child: const Text('zoomOut'),
),
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.zoomTo(16.0),
);
},
child: const Text('zoomTo'),
),
],
),
],
)
],
);
}
}