-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathGoogleMaps.dart
179 lines (172 loc) · 5.61 KB
/
GoogleMaps.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
//For more info...
//https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/example/lib
void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Google Maps demo')),
body: MapsDemo(),
),
));
}
class MapsDemo extends StatefulWidget {
@override
State createState() => MapsDemoState();
}
class MapsDemoState extends State<MapsDemo> {
GoogleMapController mapController;
static final LatLng center = const LatLng(32.7266, 74.8570);
@override
Widget build(BuildContext context) {
return Stack(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.center,
children: [
// LinearProgressIndicator(),
// CircularProgressIndicator(),
// RefreshProgressIndicator(),
// SpinKitThreeBounce(
// size: 50.0,
// color: Colors.black,
// ),
GoogleMap(
onMapCreated: (controller) {
mapController = controller;
},
options: GoogleMapOptions(
scrollGesturesEnabled: true,
tiltGesturesEnabled: true,
rotateGesturesEnabled: true,
myLocationEnabled: true,
compassEnabled: true,
mapType: MapType.normal,
trackCameraPosition: true,
zoomGesturesEnabled: true,
cameraPosition: const CameraPosition(
target: LatLng(-33.852, 151.211),
zoom: 11.0,
),
),
),
FloatingActionButton(
onPressed: _onAddMarkerButtonPressed,
materialTapTargetSize: MaterialTapTargetSize.padded,
backgroundColor: Colors.green,
child: const Icon(Icons.add_location, size: 36.0),
),
Positioned(
// left: 16.0,
top: 70.0,
child: FloatingActionButton(
mini: true,
onPressed: () {
mapController.updateMapOptions(
GoogleMapOptions(mapType: MapType.satellite));
},
materialTapTargetSize: MaterialTapTargetSize.padded,
backgroundColor: Colors.white10,
child: const Icon(Icons.edit_location, size: 36.0),
),
),
Positioned(
// left: 16.0,
top: 130.0,
child: FloatingActionButton(
mini: true,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) =>
locationDialog(mapController.cameraPosition));
},
materialTapTargetSize: MaterialTapTargetSize.padded,
backgroundColor: Colors.white10,
child: const Icon(Icons.my_location, size: 36.0),
),
),
Positioned(
bottom: 16.0,
left: 16.0,
child: RaisedButton(
child: Text('Move Camera'),
color: Colors.lightGreen,
onPressed: () {
mapController.animateCamera(
// CameraUpdate.newLatLng(LatLng(32.7266, 74.8570)),
CameraUpdate.newCameraPosition(CameraPosition(
target: LatLng(32.7266, 74.8570),
// bearing: 90.0
zoom: 15.0,
tilt: 30.0)));
},
),
),
// Positioned(
// bottom: 16.0,
// right: 26.0,
// child: RaisedButton(
// child: Text('Mark Pos'),
// color: Colors.lightGreen,
// onPressed: () {
// mapController.addMarker(
// MarkerOptions(
// position: LatLng(
// center.latitude,
// center.longitude,
// ),
// icon: BitmapDescriptor.defaultMarkerWithHue(
// BitmapDescriptor.hueGreen,
// ),
// // icon: BitmapDescriptor.defaultMarker,
// zIndex: 15.0,
// // rotation: 300.0, rotates the marker
// infoWindowText: InfoWindowText('My Location', '*'),
// infoWindowAnchor: Offset(1.0, 0.0),
// alpha: 0.5),
// );
// },
// ),
// )
],
);
}
void _onAddMarkerButtonPressed() {
mapController.addMarker(
MarkerOptions(
position: LatLng(
mapController.cameraPosition.target.latitude,
mapController.cameraPosition.target.longitude,
),
infoWindowText: InfoWindowText('My Location', 'Home'),
icon: BitmapDescriptor.defaultMarker,
),
);
}
Widget locationDialog(CameraPosition pos) {
return CupertinoAlertDialog(
title: new Text("Current Location"),
content: Column(
children: [
Text('latitude : ' + pos.target.latitude.toInt().toString()),
Text('longitude : ' + pos.target.longitude.toInt().toString())
],
),
actions: <Widget>[
new CupertinoDialogAction(
child: const Text('Discard'),
isDestructiveAction: true,
onPressed: () {
Navigator.pop(context, 'Discard');
}),
new CupertinoDialogAction(
child: const Text('Cancel'),
isDefaultAction: true,
onPressed: () {
Navigator.pop(context, 'Cancel');
}),
],
);
}
}