reason

迁移到百度地图

...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
3 package="pub.yiyan.parlando.Parlando"> 3 package="pub.yiyan.parlando.Parlando">
4 4
5 <application 5 <application
6 + android:name=".MyApplication"
6 android:icon="@mipmap/ic_launcher" 7 android:icon="@mipmap/ic_launcher"
7 android:label="Parlando" 8 android:label="Parlando"
8 android:requestLegacyExternalStorage="true" 9 android:requestLegacyExternalStorage="true"
...@@ -55,6 +56,9 @@ ...@@ -55,6 +56,9 @@
55 <meta-data 56 <meta-data
56 android:name="com.amap.api.v2.apikey" 57 android:name="com.amap.api.v2.apikey"
57 android:value="038a8a2d7280a244b5c51d517023ede3" /> 58 android:value="038a8a2d7280a244b5c51d517023ede3" />
59 + <meta-data
60 + android:name="com.baidu.lbsapi.API_KEY"
61 + android:value="WSVybPeSZqwIGLYXjN44mighexoFX6Dn" />
58 </application> 62 </application>
59 63
60 <queries> 64 <queries>
......
1 +package pub.yiyan.parlando.Parlando
2 +
3 +import com.baidu.mapapi.base.BmfMapApplication
4 +
5 +class MyApplication : BmfMapApplication() {
6 + override fun onCreate() {
7 + super.onCreate();
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -25,6 +25,10 @@ import 'util/device_utils.dart'; ...@@ -25,6 +25,10 @@ import 'util/device_utils.dart';
25 import 'util/handle_error_utils.dart'; 25 import 'util/handle_error_utils.dart';
26 import 'util/log_utils.dart'; 26 import 'util/log_utils.dart';
27 import 'util/theme_utils.dart'; 27 import 'util/theme_utils.dart';
28 +import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'
29 + show BMFMapSDK, BMF_COORD_TYPE;
30 +import 'package:permission_handler/permission_handler.dart';
31 +import 'package:flutter_bmflocation/flutter_bmflocation.dart';
28 32
29 /// 33 ///
30 /// 配置本地化的方法 34 /// 配置本地化的方法
...@@ -82,6 +86,27 @@ Future<void> main() async { ...@@ -82,6 +86,27 @@ Future<void> main() async {
82 ); 86 );
83 SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle); 87 SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
84 } 88 }
89 +
90 + /// 动态申请定位权限
91 + requestPermission();
92 +
93 + LocationFlutterPlugin myLocPlugin = LocationFlutterPlugin();
94 +
95 + /// 设置用户是否同意SDK隐私协议
96 + /// since 3.1.0 开发者必须设置
97 + 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 + }
85 } 110 }
86 111
87 class MyApp extends StatelessWidget { 112 class MyApp extends StatelessWidget {
...@@ -205,3 +230,31 @@ class MyApp extends StatelessWidget { ...@@ -205,3 +230,31 @@ class MyApp extends StatelessWidget {
205 ); 230 );
206 } 231 }
207 } 232 }
233 +
234 +// 动态申请定位权限
235 +void requestPermission() async {
236 + // 申请权限
237 + bool hasLocationPermission = await requestLocationPermission();
238 + if (hasLocationPermission) {
239 + // 权限申请通过
240 + } else {}
241 +}
242 +
243 +/// 申请定位权限
244 +/// 授予定位权限返回true, 否则返回false
245 +Future<bool> requestLocationPermission() async {
246 + //获取当前的权限
247 + var status = await Permission.location.status;
248 + if (status == PermissionStatus.granted) {
249 + //已经授权
250 + return true;
251 + } else {
252 + //未授权则发起一次申请
253 + status = await Permission.location.request();
254 + if (status == PermissionStatus.granted) {
255 + return true;
256 + } else {
257 + return false;
258 + }
259 + }
260 +}
...\ No newline at end of file ...\ No newline at end of file
......
1 +import 'dart:convert';
2 +import 'package:Parlando/map/poi_search_model.dart';
3 +import 'package:flutter/services.dart';
4 +
5 +import 'amap_2d_view.dart';
6 +import 'interface/amap_2d_controller.dart';
7 +
8 +class AMap2DMobileController extends AMap2DController {
9 + AMap2DMobileController(
10 + int id,
11 + this._widget,
12 + ) : _channel = MethodChannel('plugins.weilu/flutter_2d_amap_$id') {
13 + _channel.setMethodCallHandler(_handleMethod);
14 + }
15 +
16 + final MethodChannel _channel;
17 +
18 + final AMap2DView _widget;
19 +
20 + Future<dynamic> _handleMethod(MethodCall call) async {
21 + final String method = call.method;
22 + switch (method) {
23 + case 'poiSearchResult':
24 + {
25 + if (_widget.onPoiSearched != null) {
26 + final Map args = call.arguments as Map<dynamic, dynamic>;
27 + final List<PoiSearch> list = [];
28 + for (var value
29 + in (json.decode(args['poiSearchResult'] as String) as List)) {
30 + list.add(PoiSearch.fromJsonMap(value as Map<String, dynamic>));
31 + }
32 + _widget.onPoiSearched!(list);
33 + }
34 + return Future<dynamic>.value('');
35 + }
36 + }
37 + return Future<dynamic>.value('');
38 + }
39 +
40 + /// city:cityName(中文或中文全拼)、cityCode均可
41 + @override
42 + Future<void> search(String keyWord, {String city = ''}) async {
43 + return _channel.invokeMethod('search', <String, dynamic>{
44 + 'keyWord': keyWord,
45 + 'city': city,
46 + });
47 + }
48 +
49 + @override
50 + Future<void> move(String lat, String lon) async {
51 + return _channel
52 + .invokeMethod('move', <String, dynamic>{'lat': lat, 'lon': lon});
53 + }
54 +
55 + @override
56 + Future<void> location() async {
57 + return _channel.invokeMethod('location');
58 + }
59 +}
1 +import 'package:flutter/material.dart';
2 +import 'amap_2d_view_state.dart';
3 +import 'interface/amap_2d_controller.dart';
4 +import 'poi_search_model.dart';
5 +
6 +typedef AMap2DViewCreatedCallback = void Function(AMap2DController controller);
7 +
8 +class AMap2DView extends StatefulWidget {
9 + const AMap2DView({
10 + Key? key,
11 + this.isPoiSearch = true,
12 + this.onPoiSearched,
13 + this.onAMap2DViewCreated,
14 + }) : super(key: key);
15 +
16 + final bool isPoiSearch;
17 + final AMap2DViewCreatedCallback? onAMap2DViewCreated;
18 + final Function(List<PoiSearch>)? onPoiSearched;
19 +
20 + @override
21 + AMap2DViewState createState() => AMap2DViewState();
22 +}
1 +import 'package:flutter/foundation.dart';
2 +import 'package:flutter/widgets.dart';
3 +
4 +import 'amap_2d_view.dart';
5 +
6 +class AMap2DViewState extends State<AMap2DView> {
7 + @override
8 + Widget build(BuildContext context) {
9 + return Text(
10 + '$defaultTargetPlatform is not yet supported by the flutter_2d_amap plugin');
11 + }
12 +}
1 +import 'dart:async';
2 +import 'dart:io';
3 +
4 +import 'package:flutter/foundation.dart';
5 +import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'
6 + show BMFMapSDK, BMF_COORD_TYPE;
7 +
8 +class Flutter2dAMap {
9 + static String _webKey = '';
10 +
11 + static String get webKey => _webKey;
12 +
13 + static Future<bool?> setApiKey(
14 + {String iOSKey = '', String webKey = ''}) async {
15 + if (kIsWeb) {
16 + _webKey = webKey;
17 + } else {
18 + // 百度地图sdk初始化鉴权
19 + if (Platform.isIOS) {
20 + BMFMapSDK.setApiKeyAndCoordType(
21 + 'rMsgMvYERM9zHDDdaipk34oBx7yoaGQh', BMF_COORD_TYPE.BD09LL);
22 + } else if (Platform.isAndroid) {
23 + // Android 目前不支持接口设置Apikey,
24 + // 请在主工程的Manifest文件里设置,详细配置方法请参考官网(https://lbsyun.baidu.com/)demo
25 + BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL);
26 + }
27 + }
28 + return Future.value(true);
29 + }
30 +
31 + /// 更新同意隐私状态,需要在初始化地图之前完成
32 + static Future<void> updatePrivacy(bool isAgree) async {
33 + if (kIsWeb) {
34 + } else {
35 + if (Platform.isIOS || Platform.isAndroid) {
36 + BMFMapSDK.setAgreePrivacy(true);
37 + }
38 + }
39 + }
40 +}
1 +abstract class AMap2DController {
2 + /// city:cityName(中文或中文全拼)、cityCode均可
3 + Future<void> search(String keyWord, {String city = ''});
4 +
5 + Future<void> move(String lat, String lon);
6 +
7 + Future<void> location();
8 +}
1 +class PoiSearch {
2 + PoiSearch({
3 + this.cityCode,
4 + this.cityName,
5 + this.provinceName,
6 + this.title,
7 + this.adName,
8 + this.provinceCode,
9 + this.latitude,
10 + this.longitude,
11 + });
12 +
13 + PoiSearch.fromJsonMap(Map<String, dynamic> map)
14 + : cityCode = map['cityCode'] as String?,
15 + cityName = map['cityName'] as String?,
16 + provinceName = map['provinceName'] as String?,
17 + title = map['title'] as String?,
18 + adName = map['adName'] as String?,
19 + provinceCode = map['provinceCode'] as String?,
20 + latitude = map['latitude'] as String?,
21 + longitude = map['longitude'] as String?;
22 +
23 + String? cityCode;
24 + String? cityName;
25 + String? provinceName;
26 + String? title;
27 + String? adName;
28 + String? provinceCode;
29 + String? latitude;
30 + String? longitude;
31 +
32 + Map<String, dynamic> toJson() {
33 + final Map<String, dynamic> data = <String, dynamic>{};
34 + data['cityCode'] = cityCode;
35 + data['cityName'] = cityName;
36 + data['provinceName'] = provinceName;
37 + data['title'] = title;
38 + data['adName'] = adName;
39 + data['provinceCode'] = provinceCode;
40 + data['latitude'] = latitude;
41 + data['longitude'] = longitude;
42 + return data;
43 + }
44 +}
...@@ -5,7 +5,6 @@ import 'package:Parlando/util/toast_utils.dart'; ...@@ -5,7 +5,6 @@ import 'package:Parlando/util/toast_utils.dart';
5 import 'package:dio/dio.dart'; 5 import 'package:dio/dio.dart';
6 import 'package:flutter/cupertino.dart'; 6 import 'package:flutter/cupertino.dart';
7 import 'package:flutter/material.dart'; 7 import 'package:flutter/material.dart';
8 -import 'package:flutter_2d_amap/flutter_2d_amap.dart';
9 import 'package:Parlando/poem/provider/lang_sort_provider.dart'; 8 import 'package:Parlando/poem/provider/lang_sort_provider.dart';
10 import 'package:Parlando/poem/widgets/lang_sort_bottom_sheet.dart'; 9 import 'package:Parlando/poem/widgets/lang_sort_bottom_sheet.dart';
11 import 'package:Parlando/res/resources.dart'; 10 import 'package:Parlando/res/resources.dart';
...@@ -17,6 +16,7 @@ import 'package:Parlando/extension/int_extension.dart'; ...@@ -17,6 +16,7 @@ import 'package:Parlando/extension/int_extension.dart';
17 import 'package:getwidget/getwidget.dart'; 16 import 'package:getwidget/getwidget.dart';
18 import 'package:path_provider/path_provider.dart'; 17 import 'package:path_provider/path_provider.dart';
19 18
19 +import '../../map/poi_search_model.dart';
20 import '../poem_router.dart'; 20 import '../poem_router.dart';
21 21
22 class PoemPublish extends StatefulWidget { 22 class PoemPublish extends StatefulWidget {
......
1 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
2 -import 'package:flutter_2d_amap/flutter_2d_amap.dart';
3 import 'package:Parlando/routers/fluro_navigator.dart'; 2 import 'package:Parlando/routers/fluro_navigator.dart';
4 import 'package:Parlando/util/toast_utils.dart'; 3 import 'package:Parlando/util/toast_utils.dart';
5 import 'package:Parlando/widgets/my_button.dart'; 4 import 'package:Parlando/widgets/my_button.dart';
6 import 'package:Parlando/widgets/search_bar.dart'; 5 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';
9 +import '../../map/flutter_2d_amap.dart';
10 +import '../../map/interface/amap_2d_controller.dart';
11 +import '../../map/poi_search_model.dart';
7 12
8 class AddressSelectPage extends StatefulWidget { 13 class AddressSelectPage extends StatefulWidget {
9 const AddressSelectPage({Key? key}) : super(key: key); 14 const AddressSelectPage({Key? key}) : super(key: key);
...@@ -17,6 +22,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -17,6 +22,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
17 int _index = 0; 22 int _index = 0;
18 final ScrollController _controller = ScrollController(); 23 final ScrollController _controller = ScrollController();
19 AMap2DController? _aMap2DController; 24 AMap2DController? _aMap2DController;
25 + late BMFMapController myMapController;
20 26
21 @override 27 @override
22 void dispose() { 28 void dispose() {
...@@ -33,6 +39,25 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -33,6 +39,25 @@ class AddressSelectPageState extends State<AddressSelectPage> {
33 ); 39 );
34 } 40 }
35 41
42 + /// 创建完成回调
43 + void onBMFMapCreated(BMFMapController controller) {
44 + myMapController = controller;
45 +
46 + /// 地图加载回调
47 + myMapController.setMapDidLoadCallback(callback: () {
48 + print('mapDidLoad-地图加载完成');
49 + });
50 + }
51 +
52 + /// 设置地图参数
53 + BMFMapOptions initMapOptions() {
54 + BMFMapOptions mapOptions = BMFMapOptions(
55 + center: BMFCoordinate(39.917215, 116.380341),
56 + zoomLevel: 12,
57 + );
58 + return mapOptions;
59 + }
60 +
36 @override 61 @override
37 Widget build(BuildContext context) { 62 Widget build(BuildContext context) {
38 return Scaffold( 63 return Scaffold(
...@@ -51,18 +76,9 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -51,18 +76,9 @@ class AddressSelectPageState extends State<AddressSelectPage> {
51 children: <Widget>[ 76 children: <Widget>[
52 Expanded( 77 Expanded(
53 flex: 9, 78 flex: 9,
54 - child: AMap2DView( 79 + child: BMFMapWidget(
55 - onPoiSearched: (result) { 80 + onBMFMapCreated: onBMFMapCreated,
56 - _controller.animateTo(0.0, 81 + mapOptions: initMapOptions(),
57 - duration: const Duration(milliseconds: 10),
58 - curve: Curves.ease);
59 - _index = 0;
60 - _list = result;
61 - setState(() {});
62 - },
63 - onAMap2DViewCreated: (controller) {
64 - _aMap2DController = controller;
65 - },
66 ), 82 ),
67 ), 83 ),
68 Expanded( 84 Expanded(
......
...@@ -391,15 +391,20 @@ packages: ...@@ -391,15 +391,20 @@ packages:
391 description: flutter 391 description: flutter
392 source: sdk 392 source: sdk
393 version: "0.0.0" 393 version: "0.0.0"
394 - flutter_2d_amap: 394 + flutter_baidu_mapapi_base:
395 + dependency: transitive
396 + description:
397 + name: flutter_baidu_mapapi_base
398 + url: "https://pub.flutter-io.cn"
399 + source: hosted
400 + version: "3.2.0"
401 + flutter_baidu_mapapi_map:
395 dependency: "direct main" 402 dependency: "direct main"
396 description: 403 description:
397 - path: "." 404 + name: flutter_baidu_mapapi_map
398 - ref: "597a0538" 405 + url: "https://pub.flutter-io.cn"
399 - resolved-ref: "597a05386700e1cf854ad9b56fe21b103c669f62" 406 + source: hosted
400 - url: "https://gitee.com/reasonpun/flutter_2d_amap.git" 407 + version: "3.2.1"
401 - source: git
402 - version: "0.2.0+2"
403 flutter_blurhash: 408 flutter_blurhash:
404 dependency: transitive 409 dependency: transitive
405 description: 410 description:
...@@ -407,6 +412,13 @@ packages: ...@@ -407,6 +412,13 @@ packages:
407 url: "https://pub.flutter-io.cn" 412 url: "https://pub.flutter-io.cn"
408 source: hosted 413 source: hosted
409 version: "0.7.0" 414 version: "0.7.0"
415 + flutter_bmflocation:
416 + dependency: "direct main"
417 + description:
418 + name: flutter_bmflocation
419 + url: "https://pub.flutter-io.cn"
420 + source: hosted
421 + version: "3.2.0"
410 flutter_cache_manager: 422 flutter_cache_manager:
411 dependency: transitive 423 dependency: transitive
412 description: 424 description:
......
...@@ -79,11 +79,6 @@ dependencies: ...@@ -79,11 +79,6 @@ dependencies:
79 # The following adds the Cupertino Icons font to your application. 79 # The following adds the Cupertino Icons font to your application.
80 # Use with the CupertinoIcons class for iOS style icons. 80 # Use with the CupertinoIcons class for iOS style icons.
81 cupertino_icons: ^1.0.2 81 cupertino_icons: ^1.0.2
82 - # 高德2D地图插件(支持Web) https://github.com/simplezhli/flutter_2d_amap
83 - flutter_2d_amap:
84 - git:
85 - ref: '597a0538'
86 - url: 'https://gitee.com/reasonpun/flutter_2d_amap.git'
87 82
88 # tiktok 83 # tiktok
89 video_player: ^2.4.5 84 video_player: ^2.4.5
...@@ -129,6 +124,8 @@ dependencies: ...@@ -129,6 +124,8 @@ dependencies:
129 124
130 google_fonts: ^3.0.1 125 google_fonts: ^3.0.1
131 wakelock: ^0.6.1+2 126 wakelock: ^0.6.1+2
127 + flutter_baidu_mapapi_map: ^3.2.1
128 + flutter_bmflocation: ^3.2.0
132 129
133 dependency_overrides: 130 dependency_overrides:
134 decimal: 1.5.0 131 decimal: 1.5.0
......