show_map_page.dart
6.5 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// // import 'package:amap_flutter_location/amap_location_option.dart';
// import 'package:amap_flutter_location_ohos/amap_location_option.dart';
// import 'package:flutter/material.dart';
// import 'dart:async';
// import 'package:amap_flutter_location_ohos/amap_flutter_location_ohos.dart';
// // import 'package:permission_handler_ohos/permission_handler_ohos.dart';
// import 'package:fluttertoast/fluttertoast.dart';
// import 'package:one_key/pages/create_store/show_map_page2.dart';
// import 'package:permission_handler/permission_handler.dart';
// import 'show_map_page.dart';
// void main() {
// runApp(MaterialApp(
// home: const MyApp(),
// debugShowCheckedModeBanner: false,
// ));
// }
// class MyApp extends StatefulWidget {
// const MyApp({super.key});
// @override
// State<MyApp> createState() => _MyAppState();
// }
// class _MyAppState extends State<MyApp> {
// StreamSubscription<Map<String, Object>>? _locationListener;
// Map<String, Object>? _locationResult;
// final AMapFlutterLocation _locationPlugin = AMapFlutterLocation();
// @override
// void initState() {
// super.initState();
// // 同意隐私政策
// AMapFlutterLocation.updatePrivacyShow(true, true);
// AMapFlutterLocation.updatePrivacyAgree(true);
// AMapFlutterLocation.setApiKey("1dbf56e2e8a4d0e4cdc2df9efd36bc71",
// "dfb64c0463cb53927914364b5c09aba0", "2e36edc989da10f1010af27ba2ec3557");
// ///注册定位结果监听
// _locationListener = _locationPlugin
// .onLocationChanged()
// .listen((Map<String, Object> result) {
// setState(() {
// _locationResult = result;
// });
// });
// }
// ///设置定位参数
// void _setLocationOption() {
// AMapLocationOption locationOption = AMapLocationOption();
// ///是否单次定位
// locationOption.onceLocation = false;
// ///是否需要返回逆地理信息
// locationOption.needAddress = true;
// ///逆地理信息的语言类型
// locationOption.geoLanguage = GeoLanguage.DEFAULT;
// locationOption.desiredLocationAccuracyAuthorizationMode =
// AMapLocationAccuracyAuthorizationMode.ReduceAccuracy;
// locationOption.fullAccuracyPurposeKey = "AMapLocationScene";
// ///设置Android端连续定位的定位间隔
// locationOption.locationInterval = 2000;
// ///设置Android端的定位模式<br>
// ///可选值:<br>
// ///<li>[AMapLocationMode.Battery_Saving]</li>
// ///<li>[AMapLocationMode.Device_Sensors]</li>
// ///<li>[AMapLocationMode.Hight_Accuracy]</li>
// locationOption.locationMode = AMapLocationMode.Hight_Accuracy;
// ///设置iOS端的定位最小更新距离<br>
// locationOption.distanceFilter = -1;
// ///设置iOS端期望的定位精度
// /// 可选值:<br>
// /// <li>[DesiredAccuracy.Best] 最高精度</li>
// /// <li>[DesiredAccuracy.BestForNavigation] 适用于导航场景的高精度 </li>
// /// <li>[DesiredAccuracy.NearestTenMeters] 10米 </li>
// /// <li>[DesiredAccuracy.Kilometer] 1000米</li>
// /// <li>[DesiredAccuracy.ThreeKilometers] 3000米</li>
// locationOption.desiredAccuracy = DesiredAccuracy.Best;
// ///设置iOS端是否允许系统暂停定位
// locationOption.pausesLocationUpdatesAutomatically = false;
// ///将定位参数设置给定位插件
// _locationPlugin.setLocationOption(locationOption);
// }
// ///开始定位
// void _startLocation() {
// ///开始定位之前设置定位参数
// _setLocationOption();
// _locationPlugin.startLocation();
// }
// ///停止定位
// void _stopLocation() {
// _locationPlugin.stopLocation();
// }
// void _showMapPage() {
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) => const ShowMapPage2()),
// );
// }
// @override
// void dispose() {
// super.dispose();
// ///移除定位监听
// if (null != _locationListener) {
// _locationListener?.cancel();
// }
// ///销毁定位
// _locationPlugin.destroy();
// }
// @override
// Widget build(BuildContext context) {
// List<Widget> widgets = <Widget>[];
// if (_locationResult != null) {
// _locationResult?.forEach((key, value) {
// widgets.add(_resultWidget(key, value));
// });
// }
// widgets.addAll([
// // TextButton(
// // onPressed: () async {
// // final PermissionStatus status =
// // await PermissionStatus.che(
// // PermissionOhos.location.name);
// // if (status == PermissionStatusOhos.granted) {
// // Fluttertoast.showToast(msg: "已申请");
// // } else {
// // Fluttertoast.showToast(msg: "未申请");
// // }
// // },
// // child: const Text("检查权限")),
// // TextButton(
// // onPressed: () {
// // PermissionHandlerOhos.requestPermissions([
// // 'ohos.permission.APPROXIMATELY_LOCATION',
// // 'ohos.permission.LOCATION',
// // ]).then((value) async {
// // if ((await PermissionHandlerOhos.checkPermissionStatus(
// // PermissionOhos.location.name)) ==
// // PermissionStatusOhos.granted) {
// // Fluttertoast.showToast(msg: "已申请");
// // } else {
// // Fluttertoast.showToast(msg: "未申请");
// // }
// // });
// // },
// // child: const Text("申请权限")),
// TextButton(onPressed: () => _startLocation(), child: Text("获取位置")),
// TextButton(onPressed: () => _stopLocation(), child: Text("停止获取位置")),
// TextButton(onPressed: () => _showMapPage(), child: Text("显示地图")),
// ]);
// return MaterialApp(
// home: Scaffold(
// appBar: AppBar(
// title: const Text('AMap Plugin Example App'),
// ),
// body: Column(children: widgets),
// ),
// );
// }
// Widget _resultWidget(key, value) {
// return Row(
// mainAxisSize: MainAxisSize.min,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: <Widget>[
// Container(
// alignment: Alignment.centerRight,
// width: 100.0,
// child: Text('$key :'),
// ),
// Container(width: 5.0),
// Flexible(child: Text('$value', softWrap: true)),
// ],
// );
// }
// }