Showing
5 changed files
with
124 additions
and
29 deletions
assets/images/map/icon_mark.png
0 → 100644

2.1 KB
... | @@ -89,24 +89,9 @@ Future<void> main() async { | ... | @@ -89,24 +89,9 @@ Future<void> main() async { |
89 | 89 | ||
90 | /// 动态申请定位权限 | 90 | /// 动态申请定位权限 |
91 | requestPermission(); | 91 | requestPermission(); |
92 | - | ||
93 | - LocationFlutterPlugin myLocPlugin = LocationFlutterPlugin(); | ||
94 | - | ||
95 | /// 设置用户是否同意SDK隐私协议 | 92 | /// 设置用户是否同意SDK隐私协议 |
96 | /// since 3.1.0 开发者必须设置 | 93 | /// since 3.1.0 开发者必须设置 |
97 | BMFMapSDK.setAgreePrivacy(true); | 94 | BMFMapSDK.setAgreePrivacy(true); |
98 | - myLocPlugin.setAgreePrivacy(true); | ||
99 | - | ||
100 | - // 百度地图sdk初始化鉴权 | ||
101 | - if (Platform.isIOS) { | ||
102 | - myLocPlugin.authAK('rMsgMvYERM9zHDDdaipk34oBx7yoaGQh'); | ||
103 | - BMFMapSDK.setApiKeyAndCoordType( | ||
104 | - 'rMsgMvYERM9zHDDdaipk34oBx7yoaGQh', BMF_COORD_TYPE.BD09LL); | ||
105 | - } else if (Platform.isAndroid) { | ||
106 | - // Android 目前不支持接口设置Apikey, | ||
107 | - // 请在主工程的Manifest文件里设置,详细配置方法请参考官网(https://lbsyun.baidu.com/)demo | ||
108 | - BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); | ||
109 | - } | ||
110 | } | 95 | } |
111 | 96 | ||
112 | class MyApp extends StatelessWidget { | 97 | class MyApp extends StatelessWidget { | ... | ... |
1 | +import 'dart:io'; | ||
2 | + | ||
1 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
2 | import 'package:Parlando/routers/fluro_navigator.dart'; | 4 | import 'package:Parlando/routers/fluro_navigator.dart'; |
3 | import 'package:Parlando/util/toast_utils.dart'; | 5 | import 'package:Parlando/util/toast_utils.dart'; |
4 | import 'package:Parlando/widgets/my_button.dart'; | 6 | import 'package:Parlando/widgets/my_button.dart'; |
5 | import 'package:Parlando/widgets/search_bar.dart'; | 7 | import 'package:Parlando/widgets/search_bar.dart'; |
6 | -import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; | ||
7 | - | ||
8 | import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; | 8 | import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; |
9 | -import '../../map/flutter_2d_amap.dart'; | 9 | +import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; |
10 | +import 'package:flutter_bmflocation/flutter_bmflocation.dart'; | ||
10 | import '../../map/interface/amap_2d_controller.dart'; | 11 | import '../../map/interface/amap_2d_controller.dart'; |
11 | import '../../map/poi_search_model.dart'; | 12 | import '../../map/poi_search_model.dart'; |
12 | 13 | ||
... | @@ -22,7 +23,9 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -22,7 +23,9 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
22 | int _index = 0; | 23 | int _index = 0; |
23 | final ScrollController _controller = ScrollController(); | 24 | final ScrollController _controller = ScrollController(); |
24 | AMap2DController? _aMap2DController; | 25 | AMap2DController? _aMap2DController; |
25 | - late BMFMapController myMapController; | 26 | + late BMFMapController _myMapController; |
27 | + BaiduLocation _loationResult = BaiduLocation(); | ||
28 | + LocationFlutterPlugin myLocPlugin = LocationFlutterPlugin(); | ||
26 | 29 | ||
27 | @override | 30 | @override |
28 | void dispose() { | 31 | void dispose() { |
... | @@ -33,27 +36,115 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -33,27 +36,115 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
33 | @override | 36 | @override |
34 | void initState() { | 37 | void initState() { |
35 | super.initState(); | 38 | super.initState(); |
36 | - // TODO 需要根据项目单独设置keys | 39 | + myLocPlugin.setAgreePrivacy(true); |
37 | - Flutter2dAMap.setApiKey( | 40 | + // 百度地图sdk初始化鉴权 |
38 | - iOSKey: 'd94fbf50f5bfa86cd4e793c9ed4a9a97', | 41 | + if (Platform.isIOS) { |
39 | - ); | 42 | + myLocPlugin.authAK('rMsgMvYERM9zHDDdaipk34oBx7yoaGQh'); |
43 | + BMFMapSDK.setApiKeyAndCoordType( | ||
44 | + 'rMsgMvYERM9zHDDdaipk34oBx7yoaGQh', BMF_COORD_TYPE.BD09LL); | ||
45 | + | ||
46 | + ///接受定位回调 | ||
47 | + myLocPlugin.singleLocationCallback(callback: (BaiduLocation result) { | ||
48 | + setState(() { | ||
49 | + _loationResult = result; | ||
50 | + locationFinish(); | ||
51 | + }); | ||
52 | + }); | ||
53 | + } else if (Platform.isAndroid) { | ||
54 | + // Android 目前不支持接口设置Apikey, | ||
55 | + // 请在主工程的Manifest文件里设置,详细配置方法请参考官网(https://lbsyun.baidu.com/)demo | ||
56 | + BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); | ||
57 | + myLocPlugin.seriesLocationCallback(callback: (BaiduLocation result) { | ||
58 | + setState(() { | ||
59 | + _loationResult = result; | ||
60 | + | ||
61 | + locationFinish(); | ||
62 | + myLocPlugin.stopLocation(); | ||
63 | + }); | ||
64 | + }); | ||
65 | + } | ||
66 | + | ||
67 | + ///设置定位参数 | ||
68 | + _locationAction(); | ||
69 | + _startLocation(); | ||
70 | + } | ||
71 | + | ||
72 | + void _locationAction() async { | ||
73 | + Map iosMap = initIOSOptions().getMap(); | ||
74 | + Map androidMap = initAndroidOptions().getMap(); | ||
75 | + | ||
76 | + await myLocPlugin.prepareLoc(androidMap, iosMap); | ||
77 | + } | ||
78 | + | ||
79 | + ///定位完成添加mark | ||
80 | + void locationFinish() { | ||
81 | + /// 创建BMFMarker | ||
82 | + BMFMarker marker = BMFMarker.icon( | ||
83 | + position: BMFCoordinate( | ||
84 | + _loationResult.latitude ?? 0.0, _loationResult.longitude ?? 0.0), | ||
85 | + title: 'flutterMaker', | ||
86 | + identifier: 'flutter_marker', | ||
87 | + icon: 'assets/images/map/icon_mark.png'); | ||
88 | + print(_loationResult.latitude.toString() + | ||
89 | + _loationResult.longitude.toString()); | ||
90 | + | ||
91 | + /// 添加Marker | ||
92 | + _myMapController.addMarker(marker); | ||
93 | + | ||
94 | + ///设置中心点 | ||
95 | + _myMapController.setCenterCoordinate( | ||
96 | + BMFCoordinate( | ||
97 | + _loationResult.latitude ?? 0.0, _loationResult.longitude ?? 0.0), | ||
98 | + false); | ||
99 | + } | ||
100 | + | ||
101 | + /// 设置地图参数 | ||
102 | + BaiduLocationAndroidOption initAndroidOptions() { | ||
103 | + BaiduLocationAndroidOption options = BaiduLocationAndroidOption( | ||
104 | + coorType: 'bd09ll', | ||
105 | + locationMode: BMFLocationMode.hightAccuracy, | ||
106 | + isNeedAddress: true, | ||
107 | + isNeedAltitude: true, | ||
108 | + isNeedLocationPoiList: true, | ||
109 | + isNeedNewVersionRgc: true, | ||
110 | + isNeedLocationDescribe: true, | ||
111 | + openGps: true, | ||
112 | + locationPurpose: BMFLocationPurpose.sport, | ||
113 | + coordType: BMFLocationCoordType.bd09ll); | ||
114 | + return options; | ||
115 | + } | ||
116 | + | ||
117 | + BaiduLocationIOSOption initIOSOptions() { | ||
118 | + BaiduLocationIOSOption options = BaiduLocationIOSOption( | ||
119 | + coordType: BMFLocationCoordType.bd09ll, | ||
120 | + BMKLocationCoordinateType: 'BMKLocationCoordinateTypeBMK09LL', | ||
121 | + desiredAccuracy: BMFDesiredAccuracy.best); | ||
122 | + return options; | ||
123 | + } | ||
124 | + | ||
125 | + /// 启动定位 | ||
126 | + Future<void> _startLocation() async { | ||
127 | + if (Platform.isIOS) { | ||
128 | + await myLocPlugin | ||
129 | + .singleLocation({'isReGeocode': true, 'isNetworkState': true}); | ||
130 | + } else if (Platform.isAndroid) { | ||
131 | + await myLocPlugin.startLocation(); | ||
132 | + } | ||
40 | } | 133 | } |
41 | 134 | ||
42 | /// 创建完成回调 | 135 | /// 创建完成回调 |
43 | void onBMFMapCreated(BMFMapController controller) { | 136 | void onBMFMapCreated(BMFMapController controller) { |
44 | - myMapController = controller; | 137 | + _myMapController = controller; |
45 | 138 | ||
46 | /// 地图加载回调 | 139 | /// 地图加载回调 |
47 | - myMapController.setMapDidLoadCallback(callback: () { | 140 | + _myMapController.setMapDidLoadCallback(callback: () {}); |
48 | - print('mapDidLoad-地图加载完成'); | ||
49 | - }); | ||
50 | } | 141 | } |
51 | 142 | ||
52 | /// 设置地图参数 | 143 | /// 设置地图参数 |
53 | BMFMapOptions initMapOptions() { | 144 | BMFMapOptions initMapOptions() { |
54 | BMFMapOptions mapOptions = BMFMapOptions( | 145 | BMFMapOptions mapOptions = BMFMapOptions( |
55 | center: BMFCoordinate(39.917215, 116.380341), | 146 | center: BMFCoordinate(39.917215, 116.380341), |
56 | - zoomLevel: 12, | 147 | + zoomLevel: 18, |
57 | ); | 148 | ); |
58 | return mapOptions; | 149 | return mapOptions; |
59 | } | 150 | } |
... | @@ -77,7 +168,9 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -77,7 +168,9 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
77 | Expanded( | 168 | Expanded( |
78 | flex: 9, | 169 | flex: 9, |
79 | child: BMFMapWidget( | 170 | child: BMFMapWidget( |
80 | - onBMFMapCreated: onBMFMapCreated, | 171 | + onBMFMapCreated: (BMFMapController controller) { |
172 | + onBMFMapCreated(controller); | ||
173 | + }, | ||
81 | mapOptions: initMapOptions(), | 174 | mapOptions: initMapOptions(), |
82 | ), | 175 | ), |
83 | ), | 176 | ), | ... | ... |
... | @@ -405,6 +405,20 @@ packages: | ... | @@ -405,6 +405,20 @@ packages: |
405 | url: "https://pub.flutter-io.cn" | 405 | url: "https://pub.flutter-io.cn" |
406 | source: hosted | 406 | source: hosted |
407 | version: "3.2.1" | 407 | version: "3.2.1" |
408 | + flutter_baidu_mapapi_search: | ||
409 | + dependency: "direct main" | ||
410 | + description: | ||
411 | + name: flutter_baidu_mapapi_search | ||
412 | + url: "https://pub.flutter-io.cn" | ||
413 | + source: hosted | ||
414 | + version: "3.2.0" | ||
415 | + flutter_baidu_mapapi_utils: | ||
416 | + dependency: "direct main" | ||
417 | + description: | ||
418 | + name: flutter_baidu_mapapi_utils | ||
419 | + url: "https://pub.flutter-io.cn" | ||
420 | + source: hosted | ||
421 | + version: "3.2.0" | ||
408 | flutter_blurhash: | 422 | flutter_blurhash: |
409 | dependency: transitive | 423 | dependency: transitive |
410 | description: | 424 | description: | ... | ... |
... | @@ -125,6 +125,8 @@ dependencies: | ... | @@ -125,6 +125,8 @@ dependencies: |
125 | google_fonts: ^3.0.1 | 125 | google_fonts: ^3.0.1 |
126 | wakelock: ^0.6.1+2 | 126 | wakelock: ^0.6.1+2 |
127 | flutter_baidu_mapapi_map: ^3.2.1 | 127 | flutter_baidu_mapapi_map: ^3.2.1 |
128 | + flutter_baidu_mapapi_utils: ^3.2.0 | ||
129 | + flutter_baidu_mapapi_search: ^3.2.0 | ||
128 | flutter_bmflocation: ^3.2.0 | 130 | flutter_bmflocation: ^3.2.0 |
129 | 131 | ||
130 | dependency_overrides: | 132 | dependency_overrides: |
... | @@ -209,6 +211,7 @@ flutter: | ... | @@ -209,6 +211,7 @@ flutter: |
209 | - assets/images/category/ | 211 | - assets/images/category/ |
210 | - assets/images/membership/ | 212 | - assets/images/membership/ |
211 | - assets/images/share/ | 213 | - assets/images/share/ |
214 | + - assets/images/map/ | ||
212 | - assets/data/ | 215 | - assets/data/ |
213 | - assets/video/ | 216 | - assets/video/ |
214 | - assets/data/Data.json | 217 | - assets/data/Data.json | ... | ... |
-
Please register or login to post a comment