map_choice_point_ohos.dart
32.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
import 'dart:async';
// import 'dart:js_interop';
import 'package:flutter/material.dart';
import 'package:csp_amap_flutter_map/csp_amap_flutter_map.dart';
import 'package:csp_amap_flutter_location/amap_flutter_location.dart';
import 'package:csp_amap_flutter_location/amap_location_option.dart';
import 'package:flutter/cupertino.dart';
// import 'package:flutter/material.dart';
import 'package:csp_amap_flutter_base/csp_amap_flutter_base.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:one_key/pages/create_store/const_config.dart';
import 'package:one_key/pages/create_store/map_inputs_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/common_utils.dart';
import 'package:one_key/utils/misc.dart';
import 'package:one_key/utils/screen_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:permission_handler/permission_handler.dart';
// import '../../utils/common_utils.dart';
// import 'package:demo/resources/custom_text_style.dart';
// import 'package:demo/utils/misc.dart';
// import 'package:demo/widgets/network_state/page_loading.dart';
class MapChoicePointPage extends StatefulWidget {
final String? long;
final String? lat;
MapChoicePointPage({Key? key, this.long, this.lat}) : super(key: key);
@override
_MapChoicePointPageState createState() => _MapChoicePointPageState();
}
class _MapChoicePointPageState extends State<MapChoicePointPage> {
late AMapController _mapController;
final double _minZoom = 3;
final double _maxZoom = 20;
String? _currentZoom;
// List<Poi>? poiList;
static List<PoiModel?> list = [];
static List<PoiModel> searchlist = [];
PoiModel? poiModel;
String keyword = "";
String? address = "";
bool isloading = true;
double latitude = 39.684670899;
double longitude = 118.17630045;
double latitudeLocation = 39.684670899;
double longitudeLocation = 118.17630045;
List<MapInputsModel> inputTipDatas = [];
int page = 1;
EasyRefreshController refreshController = EasyRefreshController();
bool flag = true;
/// 存储定位结果
Map<String, Object>? _locationResult;
/// 定位结果监听器
StreamSubscription<Map<String, Object>>? _locationListener;
/// 地理位置解析结果监听器
StreamSubscription<Map<String, Object>>? _geocodeSearchListener;
/// 高德定位插件实例
final AMapFlutterLocation _locationPlugin = new AMapFlutterLocation();
@override
void initState() {
super.initState();
if (widget.long != null && widget.long != '' && widget.long != 'null') {
longitude = double.parse(widget.long!);
}
if (widget.lat != null && widget.lat != '' && widget.lat != 'null') {
latitude = double.parse(widget.lat!);
}
WidgetsBinding.instance.addPostFrameCallback((_) async {
AMapInitializer.init(context, apiKey: ConstConfig.amapApiKeys);
AMapInitializer.updatePrivacyAgree(ConstConfig.amapPrivacyStatement);
AMapFlutterLocation.setApiKey("1dbf56e2e8a4d0e4cdc2df9efd36bc71",
"dfb64c0463cb53927914364b5c09aba0",
ohosKey: "7c2081e92ec65bfffa2df0a5464f0c7b");
/// 设置是否已经包含高德隐私政策并弹窗展示显示用户查看,如果未包含或者没有弹窗展示,高德定位SDK将不会工作
///
/// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
/// <b>必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意</b>
///
/// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
///
/// [hasContains] 隐私声明中是否包含高德隐私政策说明
///
/// [hasShow] 隐私权政策是否弹窗展示告知用户
AMapFlutterLocation.updatePrivacyShow(true, true);
/// 设置是否已经取得用户同意,如果未取得用户同意,高德定位SDK将不会工作
///
/// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
///
/// <b>必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意</b>
///
/// [hasAgree] 隐私权政策是否已经取得用户同意
AMapFlutterLocation.updatePrivacyAgree(true);
_requestLocationPermission();
// ama
// let marker = new AMap.Marker({//添加标记点
// position: this.position,
// map: map
});
_geocodeSearchListener = _locationPlugin
.onGeocodeSearchChange()
.listen((Map<String, Object> result) {
// setState(() {
if (result.containsKey('errorCode')) {
Utils.showToast(result['errorInfo'].toString());
} else {
_locationResult = result;
print(_locationResult);
}
});
/// 注册定位结果监听
/// 通过监听器接收定位结果并更新UI
_locationListener = _locationPlugin
.onLocationChanged()
.listen((Map<String, Object> result) {
// setState(() {
if (result.containsKey('errorCode')) {
Utils.showToast(result['errorInfo'].toString());
} else {
_locationResult = result;
print(_locationResult);
if (result['latitude'] == null || result['latitude'] == '') //网络不好,定位失败
{
// App.sp.setString("lat", "39.684670899");
// App.sp.setString("lng", "118.17630045");
} else {
if (widget.long == null ||
widget.long == '' ||
widget.long == 'null') {
latitude = double.parse(result['latitude'].toString());
longitude = double.parse(result['longitude'].toString());
// if (_mapController != null) {
_mapController.moveCamera(
CameraUpdate.newLatLng(LatLng(latitude, longitude)));
// }
page = 1;
// _loadData(LatLng(latitude, longitude));
// setState(() {});
}
latitudeLocation = latitude;
longitudeLocation = longitude;
_mapController.moveCamera(
CameraUpdate.newLatLng(LatLng(latitudeLocation, longitudeLocation)),
animated: true,
);
_loadData(LatLng(latitude, longitude));
}
}
});
}
@override
void dispose() {
super.dispose();
/// 移除定位监听
/// 防止内存泄漏
if (null != _locationListener) {
_locationListener?.cancel();
}
if (null != _geocodeSearchListener) {
_geocodeSearchListener?.cancel();
}
/// 销毁定位
/// 释放定位资源
_locationPlugin.destroy();
}
// Future<bool> checkLocationPermission() async {
// PermissionStatus permissionStatus = await Permission.location.status;
// if (permissionStatus == PermissionStatus.granted) {
// return true;
// } else {
// return false;
// }
// }
/// 检查权限并定
// _getLocationPermission() async {
// if (!(await checkPermission(Permission.location))) {
// //没有定位权限
// //申请定位权限
// _requestLocationPermission();
// } else {
// //去定位
// _requestLocationPermission();
// }
// }
/// 设置定位参数
/// 配置定位选项,如精度、频率等
void _setLocationOption() {
AMapLocationOption locationOption = new AMapLocationOption();
/// 是否单次定位
/// false表示连续定位
locationOption.onceLocation = true;
/// 是否需要返回逆地理信息
/// true表示需要返回地址信息
locationOption.needAddress = true;
/// 是否需要返回逆地理编码信息
locationOption.locatingWithReGeocode = true;
/// 逆地理信息的语言类型
/// 默认为自动适配当前系统语言
locationOption.geoLanguage = GeoLanguage.DEFAULT;
/// iOS 14定位精度权限设置
/// 设置为模糊定位精度
locationOption.desiredLocationAccuracyAuthorizationMode =
AMapLocationAccuracyAuthorizationMode.ReduceAccuracy;
/// iOS 14精确定位目的key
/// 需要与info.plist中配置一致
locationOption.fullAccuracyPurposeKey = "AMapLocationScene";
/// 设置Android端连续定位的定位间隔
/// 单位:毫秒
locationOption.locationInterval = 2000;
/// 设置Android端的定位模式
/// 可选值:
/// [AMapLocationMode.Battery_Saving] 低功耗模式
/// [AMapLocationMode.Device_Sensors] 仅设备模式
/// [AMapLocationMode.Hight_Accuracy] 高精度模式
locationOption.locationMode = AMapLocationMode.Hight_Accuracy;
/// 设置iOS端的定位最小更新距离
/// -1表示不限制距离
locationOption.distanceFilter = -1;
/// 设置iOS端期望的定位精度
/// 可选值:
/// [DesiredAccuracy.Best] 最高精度
/// [DesiredAccuracy.BestForNavigation] 适用于导航场景的高精度
/// [DesiredAccuracy.NearestTenMeters] 10米
/// [DesiredAccuracy.Kilometer] 1000米
/// [DesiredAccuracy.ThreeKilometers] 3000米
locationOption.desiredAccuracy = DesiredAccuracy.Best;
/// 设置iOS端是否允许系统暂停定位
/// false表示不允许系统暂停定位
locationOption.pausesLocationUpdatesAutomatically = false;
/// 将定位参数设置给定位插件
_locationPlugin.setLocationOption(locationOption);
}
/// 获取定位权限
_requestLocationPermission() async {
/// [hasShow] 隐私权政策是否弹窗展示告知用户
AMapFlutterLocation.updatePrivacyShow(true, true);
/// [hasAgree] 隐私权政策是否已经取得用户同意
AMapFlutterLocation.updatePrivacyAgree(true);
// await AMapFlutterLocation.instance.updatePrivacyShow(true);
// await AmapLocation.instance.updatePrivacyAgree(true);
bool canLocation = false;
if (!(await checkPermission(Permission.location))) {
//没有定位权限
//申请定位权限
canLocation = await requestPermission(Permission.location);
} else {
canLocation = true;
}
// bool canLocation = await requestPermission(Permission.location);
// 单次定位
if (canLocation) {
Future.delayed(Duration(milliseconds: 200), () async {
/// [hasShow] 隐私权政策是否弹窗展示告知用户
AMapFlutterLocation.updatePrivacyShow(true, true);
/// [hasAgree] 隐私权政策是否已经取得用户同意
AMapFlutterLocation.updatePrivacyAgree(true);
_startLocation();
// final location = await AmapLocation.instance.fetchLocation(
// // needAddress: true,
// // mode: LocationAccuracy.High,
// // timeout: Duration(seconds: 10)
// );
// if (location.city == null || location.city == '') //网络不好,定位失败
// {
// // App.sp.setString("lat", "39.684670899");
// // App.sp.setString("lng", "118.17630045");
// } else {
// if (widget.long == null ||
// widget.long == '' ||
// widget.long == 'null') {
// latitude = location.latLng!.latitude;
// longitude = location.latLng!.longitude;
// if (_controller != null) {
// _controller!.setCenterCoordinate(LatLng(
// location.latLng!.latitude, location.latLng!.longitude));
// }
// page = 1;
// _loadData(
// LatLng(location.latLng!.latitude, location.latLng!.longitude));
// setState(() {});
// }
// latitudeLocation = location.latLng!.latitude;
// longitudeLocation = location.latLng!.longitude;
// }
});
} else {
//无权限
}
}
// 开始定位
/// 设置定位参数并启动定位
void _startLocation() {
/// 开始定位之前设置定位参数
_setLocationOption();
_locationPlugin.startLocation();
}
/// 停止定位
/// 停止定位服务
void _stopLocation() {
_locationPlugin.stopLocation();
}
void onMapCreated(AMapController controller) {
// setState(() {
_mapController = controller;
// _mapController.moveCamera(
// CameraUpdate.newLatLng(LatLng(latitudeLocation, longitudeLocation)),
// animated: true,
// );
// getApprovalNumber();
// });
}
/// 获取审图号
// void getApprovalNumber() async {
// //普通地图审图号
// String mapContentApprovalNumber =
// (await _mapController.getMapContentApprovalNumber());
// //卫星地图审图号
// String satelliteImageApprovalNumber =
// (await _mapController.getSatelliteImageApprovalNumber());
// print('地图审图号(普通地图): $mapContentApprovalNumber');
// print('地图审图号(卫星地图): $satelliteImageApprovalNumber');
// }
//移动视野
// void _onCameraMove(CameraPosition cameraPosition) {
// latitude = cameraPosition.target.latitude;
// longitude = cameraPosition.target.longitude;
// page = 1;
// _loadData(cameraPosition.target);
// }
//移动地图结束
void _onCameraMoveEnd(CameraPosition cameraPosition) {
setState(() {
_currentZoom = '当前缩放级别:${cameraPosition.zoom}';
});
_mapController.moveCamera(
CameraUpdate.zoomTo(cameraPosition.zoom),
animated: true,
);
latitude = cameraPosition.target.latitude;
longitude = cameraPosition.target.longitude;
page = 1;
_loadData(cameraPosition.target);
}
@override
Widget build(BuildContext context) {
final AMapWidget amap = AMapWidget(
initialCameraPosition:
CameraPosition(target: LatLng(latitude, longitude), zoom: 16),
onMapCreated: onMapCreated,
// onCameraMove: _onCameraMove,
onCameraMoveEnd: _onCameraMoveEnd,
minMaxZoomPreference: MinMaxZoomPreference(_minZoom, _maxZoom),
scaleEnabled: true,
);
return Scaffold(
resizeToAvoidBottomInset: false, //防止底部布局被顶起
appBar: SystemAppBar(
'选择位置信息',
onTap: () {
if (Navigator.canPop(context)) {
Navigator.pop(context);
}
},
),
body: Column(
children: <Widget>[
// Theme(
// data: new
// ThemeData(
// // primaryColor: MyColours.color_438E93,
// // hintColor: MyColours.color_438E93),
// child:
// Container(
// color: MyColours.color_438E93,
// decoration: BoxDecoration(
// color: MyColours.color_438E93,
// boxShadow: [
// BoxShadow(color: Colors.white, spreadRadius: 1),
// ],
// ),
// padding: EdgeInsets.all(5),
// child:
// ),
// ),
// ListView.builder(
// shrinkWrap: true,
// itemCount: inputTipDatas.length,
// itemBuilder: (context, index) {
// InputTip inputTip = inputTipDatas[index];
// return InkWell(
// onTap: () {
// // searchAroundAddress(inputTip.name ?? '');
// // searchPoiId(inputTip.poiId ?? '');
// // _loadData(inputTip.coordinate ??
// // LatLng(latitude, longitude));
// },
// child: Container(
// child: Row(
// children: [
// Text(
// inputTip.name ?? '',
// style: TextStyle(
// fontSize: font(15),
// color: MyColours.color_515151),
// ),
// HEmptyView(10),
// Expanded(
// child: Text(
// (inputTip.district ?? '') +
// (inputTip.address ?? ''),
// style: TextStyle(
// fontSize: font(13),
// color: MyColours.color_999999),
// ),
// ),
// ],
// )));
// })
// ],
// ),
Stack(
children: [
Container(
height: w(300),
child: Stack(
children: <Widget>[
amap,
// AmapView(
// showZoomControl: false,
// /// 是否显示指南针控件
// showCompass: true,
// /// 是否显示比例尺控件
// showScaleControl: true,
// /// 是否使能缩放手势
// zoomGesturesEnabled: true,
// /// 是否使能滚动手势
// scrollGesturesEnabled: true,
// /// 是否使能旋转手势
// rotateGestureEnabled: false,
// centerCoordinate: LatLng(latitude, longitude),
// maskDelay: Duration(milliseconds: 500),
// zoomLevel: 19,
// onMapCreated: (controller) async {
// _controller = controller;
// _controller!
// .setCenterCoordinate(LatLng(latitude, longitude));
// // if (await requestPermission(PermissionGroup.location)) {
// // await controller.showMyLocation(true);
// // await controller?.showLocateControl(true);
// // final latLng = await _controller?.getLocation(
// // delay: Duration(seconds: 2));
// // await enableFluttifyLog(false); // 关闭log
// // _loadData(latLng);
// // } else {
// // //无权限
// // _showLocPemWidget();
// // }
// },
// // markers: [],
// onMapMoveEnd: (MapMove move) async {
// latitude = move.coordinate!.latitude;
// longitude = move.coordinate!.longitude;
// page = 1;
// _loadData(move.coordinate!);
// },
// ),
Center(
child: Icon(
Icons.place,
size: w(32),
color: Color(0xFFFF0000),
),
),
Positioned(
right: w(10),
bottom: w(10),
child: InkWell(
onTap: () {
_mapController.moveCamera(
CameraUpdate.newLatLng(
LatLng(latitudeLocation, longitudeLocation)),
animated: true,
);
},
child: Container(
decoration: BoxDecoration(
color: MyColours.color_ffffff,
borderRadius: BorderRadius.circular(r(5))),
padding: EdgeInsets.all(w(5)),
child: Image.asset(
Utils.getImgPath('location_map'),
width: w(25),
),
)),
)
],
),
),
Positioned(
top: w(10),
left: w(20),
right: w(20),
child: Container(
// height: w(45),
padding: EdgeInsets.symmetric(vertical: w(10)),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(r(10))),
child: TextField(
textAlignVertical: TextAlignVertical.center,
style: TextStyle(
color: MyColours.color_515151,
fontSize: font(15),
),
controller:
TextEditingController.fromValue(TextEditingValue(
// 设置内容
text: keyword,
selection: TextSelection.fromPosition(TextPosition(
affinity: TextAffinity.downstream,
offset: keyword.length)),
// 保持光标在最后
)),
decoration: InputDecoration(
// border: b,
// border: OutlineInputBorder(
// borderRadius: BorderRadius.all(Radius.circular(40)),
// ),
border: OutlineInputBorder(borderSide: BorderSide.none),
hintText: '输入关键字',
isCollapsed: true,
hintStyle: TextStyle(
color: MyColours.color_999999, fontSize: font(15)),
// contentPadding: const EdgeInsets.symmetric(
// vertical: 8, horizontal: 1),
prefixIconConstraints: BoxConstraints(maxWidth: w(40)),
prefixIcon: Padding(
padding: EdgeInsets.only(left: w(10), right: w(10)),
child: SizedBox(
width: w(30),
child: Image.asset(
Utils.getImgPath('search_black'),
))),
suffixIconConstraints: BoxConstraints(maxWidth: w(32)),
suffixIcon: InkWell(
child: Padding(
padding: EdgeInsets.only(left: w(10), right: w(10)),
child: SizedBox(
width: w(22),
child: Image.asset(
Utils.getImgPath('delete_black'),
))),
onTap: () {
keyword = "";
setState(() {});
},
),
fillColor: Colors.white,
filled: true,
),
inputFormatters: [],
//内容改变的回调
onChanged: (text) {
print('change $text');
keyword = text;
//搜索
if (text != null && text.trim().length > 0) {
JhCommonUtils.debounce(
() => _fetchInputTips(text.toString()));
}
},
//内容提交(按回车)的回调
onSubmitted: (text) {
print('submit $text');
// 触发关闭弹出来的键盘。
keyword = text;
FocusScope.of(context).requestFocus(FocusNode());
setState(() {
// isloading = true;
});
// _fetchInputTips(text.toString());
// searchAroundAddress(text.toString());
},
//按回车时调用
onEditingComplete: () {
print('onEditingComplete');
},
),
),
)
],
),
Expanded(
flex: 1,
child: Visibility(
visible: !isloading,
maintainSize: false,
maintainSemantics: false,
maintainInteractivity: false,
replacement: Center(
child: CupertinoActivityIndicator(),
),
child: EasyRefresh.custom(
controller: refreshController,
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int position) {
print("itemBuilder" + list.length.toString());
PoiModel item = list[position]!;
return InkWell(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(
top: 8, bottom: 5, left: 10),
child: Row(
children: <Widget>[
Icon(
Icons.place,
size: 20.0,
color: position == 0
? Colors.green
: Colors.grey,
),
Expanded(
child: Text(item.title,
style: TextStyle(
fontSize: 16,
color: position == 0
? Colors.green
: Color(0xFF787878))))
],
),
),
Container(
margin: EdgeInsets.only(
top: 5, bottom: 5, left: 18),
alignment: Alignment.centerLeft,
child: Text(
item.address!,
style: TextStyle(
fontSize: 14,
color: Color(0xFF646464),
),
),
),
Divider(
height: 1,
)
],
),
onTap: () async {
// await _controller.setCenterCoordinate(
// LatLng(item.latLng.latitude, item.latLng.longitude),
// zoomLevel: 16);
if (Navigator.canPop(context)) {
Navigator.pop(context, {
'address': item.address,
'lat': item.latLng!.latitude.toString(),
'lng': item.latLng!.longitude.toString()
});
}
},
);
},
childCount: list.length,
),
)
],
onRefresh: () async {
if (flag) {
page = 1;
_loadData(LatLng(latitude, longitude));
}
},
onLoad: () async {
if (flag) {
page++;
_loadData(LatLng(latitude, longitude),
showloading: false);
}
},
)),
),
],
),
);
}
_fetchInputTips(String text) async {
flag = false;
page = 1;
// setState(() {
// isloading = true;
// });
/// 逆地理编码(坐标转地址)
///
///
// await AmapLocation.instance.updatePrivacyShow(true);
// await AmapLocation.instance.updatePrivacyAgree(true);
LatLng latLng = LatLng(latitude, longitude);
address = await _locationPlugin
.onGeocodeSearch(true, [latLng.longitude, latLng.latitude]);
// await AmapLocation.instance.updatePrivacyShow(true);
// await AmapLocation.instance.updatePrivacyAgree(true);
List<dynamic> temp = await _locationPlugin.doInputtipsRequest(
text,
city: "",
);
inputTipDatas = [];
temp.forEach((element) {
inputTipDatas.add(MapInputsModel.fromJson(element));
});
print(inputTipDatas);
poiModel = new PoiModel("当前位置", address, latLng);
list.clear();
list.add(poiModel);
for (var inputTip in inputTipDatas) {
String? title = await inputTip.name ?? '';
String? cityStr = (inputTip.district ?? '') + (inputTip.city ?? '');
// LatLng? latLng = await inputTip.point;
list.add(new PoiModel(title.toString(), cityStr, latLng));
}
print(list);
setState(() {
// isloading = false;
});
}
void _loadData(LatLng latLng, {showloading = true}) async {
flag = true;
setState(() {
if (showloading) {
isloading = true;
}
});
/// 逆地理编码(坐标转地址)
///
///
///
// await AmapLocation.instance.updatePrivacyShow(true);
// await AmapLocation.instance.updatePrivacyAgree(true);
if (page == 1) {
address = await _locationPlugin
.onGeocodeSearch(true, [latLng.longitude, latLng.latitude]);
poiModel = new PoiModel("当前位置", address, latLng);
list.clear();
list.add(poiModel);
}
// final poiList
List<dynamic> temp = await _locationPlugin.poiSearchAround(
keyword, latLng.longitude, latLng.latitude);
List<MapRoundSearchModel> searchData = [];
temp.forEach((element) {
searchData.add(MapRoundSearchModel.fromJson(element));
});
print(searchData);
for (var poi in searchData) {
String? title = await poi.title;
String? cityName = await poi.cityName;
String? provinceName = await poi.provinceName;
String? snippet = await poi.snippet;
String? adName = await poi.adName;
LatLng? latLng = LatLng(poi.latitude ?? 0, poi.longitude ?? 0);
String? bussniss = poi.businessArea;
list.add(new PoiModel(
title.toString(),
provinceName.toString() +
cityName.toString() +
adName.toString() +
// address.toString() +
bussniss.toString() +
snippet.toString(),
latLng));
}
setState(() {
if (showloading) {
isloading = false;
}
});
}
// void searchPoiId(String text) async {
// await AmapLocation.instance.updatePrivacyShow(true);
// await AmapLocation.instance.updatePrivacyAgree(true);
// Poi? poi = await AmapSearch.instance.searchPoiId(
// text,
// );
// print(poi);
// }
// void searchAroundAddress(String text) async {
// await AmapLocation.instance.updatePrivacyShow(true);
// await AmapLocation.instance.updatePrivacyAgree(true);
// final poiList = await AmapSearch.instance.searchKeyword(
// text,
// city: "",
// );
// // final poiList = await AmapSearch.instance.searchAround(
// // LatLng(latitude, longitude),
// // city: "",
// // radius: 100000000000000
// // );
// list.clear();
// list.add(poiModel);
// for (var poi in poiList) {
// String? title = await poi.title;
// LatLng? latLng = await poi.latLng;
// String? cityName = await poi.cityName;
// String? provinceName = await poi.provinceName;
// String? address = await poi.address;
// list.add(new PoiModel(
// title.toString(),
// provinceName.toString() + cityName.toString() + address.toString(),
// latLng));
// }
// setState(() {
// isloading = false;
// FocusScope.of(context).requestFocus(FocusNode());
// });
// }
}
class PoiModel {
LatLng? latLng;
String title;
String? address;
PoiModel(this.title, this.address, this.latLng);
}