-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_old.dart
107 lines (99 loc) · 3.07 KB
/
main_old.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
import 'package:flutter/material.dart';
import 'package:map_view/map_view.dart';
var api_key = "AIzaSyDrHKl8IxB4cGXIoELXQOzzZwiH1xtsRf4";
void mainOld() {
MapView.setApiKey(api_key);
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
home: new MapPage(),
));
}
class MapPage extends StatefulWidget {
@override
_MapPageState createState() => new _MapPageState();
}
class _MapPageState extends State<MapPage> {
MapView mapView = new MapView();
CameraPosition cameraPosition;
var staticMapProvider = new StaticMapProvider(api_key);
Uri staticMapUri;
List<Marker> markers = <Marker>[
new Marker("1", "BSR Restuarant", 28.421364, 77.333804,
color: Colors.amber),
new Marker("2", "Flutter Institute", 28.418684, 77.340417,
color: Colors.purple),
];
showMap() {
mapView.show(new MapOptions(
mapViewType: MapViewType.normal,
initialCameraPosition:
new CameraPosition(new Location(28.420035, 77.337628), 15.0),
showUserLocation: true,
title: "Recent Location"));
mapView.setMarkers(markers);
mapView.zoomToFit(padding: 100);
mapView.onMapTapped.listen((_) {
setState(() {
mapView.setMarkers(markers);
mapView.zoomToFit(padding: 100);
});
});
}
@override
void initState() {
// TODO: implement initState
super.initState();
cameraPosition =
new CameraPosition(new Location(28.420035, 77.337628), 2.0);
staticMapUri = staticMapProvider.getStaticUri(
new Location(28.420035, 77.337628), 12,
height: 400, width: 900, mapType: StaticMapViewType.roadmap);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text("Flutter Google maps"),
),
body: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Container(
height: 300.0,
child: new Stack(
children: <Widget>[
new Center(
child: Container(
child: new Text(
"Map should show here",
textAlign: TextAlign.center,
),
padding: const EdgeInsets.all(20.0),
),
),
new InkWell(
child: new Center(
child: new Image.network(staticMapUri.toString()),
),
onTap: showMap,
)
],
),
),
new Container(
padding: new EdgeInsets.only(top: 10.0),
child: new Text(
"Tap the map to interact",
style: new TextStyle(fontWeight: FontWeight.bold),
),
),
new Container(
padding: new EdgeInsets.only(top: 25.0),
child: new Text(
"Camera Position: \n\nLat: ${cameraPosition.center.latitude}\n\nLng:${cameraPosition.center.longitude}\n\nZoom: ${cameraPosition.zoom}"),
),
],
),
);
}
}