Showing
13 changed files
with
90 additions
and
444 deletions
| ... | @@ -3,7 +3,6 @@ | ... | @@ -3,7 +3,6 @@ |
| 3 | package="pub.yiyan.parlando.Parlando"> | 3 | package="pub.yiyan.parlando.Parlando"> |
| 4 | 4 | ||
| 5 | <application | 5 | <application |
| 6 | - android:name=".MyApplication" | ||
| 7 | android:icon="@mipmap/ic_launcher" | 6 | android:icon="@mipmap/ic_launcher" |
| 8 | android:label="Parlando" | 7 | android:label="Parlando" |
| 9 | android:requestLegacyExternalStorage="true" | 8 | android:requestLegacyExternalStorage="true" |
| ... | @@ -54,11 +53,8 @@ | ... | @@ -54,11 +53,8 @@ |
| 54 | android:name="com.facebook.sdk.ClientToken" | 53 | android:name="com.facebook.sdk.ClientToken" |
| 55 | android:value="@string/facebook_client_token" /> | 54 | android:value="@string/facebook_client_token" /> |
| 56 | <meta-data | 55 | <meta-data |
| 57 | - android:name="com.amap.api.v2.apikey" | 56 | + android:name="com.google.android.geo.API_KEY" |
| 58 | - android:value="038a8a2d7280a244b5c51d517023ede3" /> | 57 | + android:value="AIzaSyBwkClNvPHwcuieSu7NJEZVCu6JDM-tkFQ" /> |
| 59 | - <meta-data | ||
| 60 | - android:name="com.baidu.lbsapi.API_KEY" | ||
| 61 | - android:value="WSVybPeSZqwIGLYXjN44mighexoFX6Dn" /> | ||
| 62 | </application> | 58 | </application> |
| 63 | 59 | ||
| 64 | <queries> | 60 | <queries> |
| ... | @@ -76,6 +72,8 @@ | ... | @@ -76,6 +72,8 @@ |
| 76 | <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | 72 | <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> |
| 77 | <uses-permission android:name="android.permission.CAMERA" /> | 73 | <uses-permission android:name="android.permission.CAMERA" /> |
| 78 | <uses-permission android:name="android.permission.RECORD_AUDIO" /> | 74 | <uses-permission android:name="android.permission.RECORD_AUDIO" /> |
| 75 | + <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> | ||
| 76 | + <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> | ||
| 79 | <uses-permission | 77 | <uses-permission |
| 80 | android:name="android.permission.QUERY_ALL_PACKAGES" | 78 | android:name="android.permission.QUERY_ALL_PACKAGES" |
| 81 | tools:node="remove" /> | 79 | tools:node="remove" /> | ... | ... |
| ... | @@ -25,8 +25,6 @@ import 'util/device_utils.dart'; | ... | @@ -25,8 +25,6 @@ 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'; | 28 | import 'package:permission_handler/permission_handler.dart'; |
| 31 | 29 | ||
| 32 | /// | 30 | /// |
| ... | @@ -88,9 +86,6 @@ Future<void> main() async { | ... | @@ -88,9 +86,6 @@ Future<void> main() async { |
| 88 | 86 | ||
| 89 | /// 动态申请定位权限 | 87 | /// 动态申请定位权限 |
| 90 | requestPermission(); | 88 | requestPermission(); |
| 91 | - /// 设置用户是否同意SDK隐私协议 | ||
| 92 | - /// since 3.1.0 开发者必须设置 | ||
| 93 | - BMFMapSDK.setAgreePrivacy(true); | ||
| 94 | } | 89 | } |
| 95 | 90 | ||
| 96 | class MyApp extends StatelessWidget { | 91 | class MyApp extends StatelessWidget { | ... | ... |
lib/map/amap_2d_controller.dart
deleted
100644 → 0
| 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 | -} |
lib/map/amap_2d_view.dart
deleted
100644 → 0
| 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 | -} |
lib/map/amap_2d_view_state.dart
deleted
100644 → 0
| 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 | -} |
lib/map/flutter_2d_amap.dart
deleted
100644 → 0
| 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 | -} |
lib/map/poi_search_model.dart
deleted
100644 → 0
| 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 | -} |
| ... | @@ -13,7 +13,6 @@ import 'package:Parlando/routers/routers.dart'; | ... | @@ -13,7 +13,6 @@ import 'package:Parlando/routers/routers.dart'; |
| 13 | import 'package:Parlando/widgets/my_app_bar.dart'; | 13 | import 'package:Parlando/widgets/my_app_bar.dart'; |
| 14 | 14 | ||
| 15 | import 'package:Parlando/extension/int_extension.dart'; | 15 | import 'package:Parlando/extension/int_extension.dart'; |
| 16 | -import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.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 | ||
| ... | @@ -110,12 +109,12 @@ class PoemPublishState extends State<PoemPublish> { | ... | @@ -110,12 +109,12 @@ class PoemPublishState extends State<PoemPublish> { |
| 110 | NavigatorUtils.pushResult( | 109 | NavigatorUtils.pushResult( |
| 111 | context, PoemRouter.addressSelectPage, (result) { | 110 | context, PoemRouter.addressSelectPage, (result) { |
| 112 | setState(() { | 111 | setState(() { |
| 113 | - final BMFSuggestionInfo model = | 112 | + // final BMFSuggestionInfo model = |
| 114 | - result as BMFSuggestionInfo; | 113 | + // result as BMFSuggestionInfo; |
| 115 | - _longitude = model.location!.longitude.toString(); | 114 | + // _longitude = model.location!.longitude.toString(); |
| 116 | - _latitude = model.location!.latitude.toString(); | 115 | + // _latitude = model.location!.latitude.toString(); |
| 117 | - _address = | 116 | + // _address = |
| 118 | - '${model.city!} ${model.district!} ${model.address!}'; | 117 | + // '${model.city!} ${model.district!} ${model.address!}'; |
| 119 | }); | 118 | }); |
| 120 | }); | 119 | }); |
| 121 | }, | 120 | }, | ... | ... |
| 1 | -import 'dart:io'; | 1 | +import 'package:location/location.dart'; |
| 2 | - | ||
| 3 | import 'package:flutter/material.dart'; | 2 | import 'package:flutter/material.dart'; |
| 4 | import 'package:Parlando/widgets/my_button.dart'; | 3 | import 'package:Parlando/widgets/my_button.dart'; |
| 5 | import 'package:Parlando/widgets/search_bar.dart'; | 4 | import 'package:Parlando/widgets/search_bar.dart'; |
| 6 | -import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; | ||
| 7 | -import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; | ||
| 8 | -import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; | ||
| 9 | -import 'package:flutter_bmflocation/flutter_bmflocation.dart'; | ||
| 10 | import 'package:getwidget/getwidget.dart'; | 5 | import 'package:getwidget/getwidget.dart'; |
| 6 | +import 'package:google_maps_flutter/google_maps_flutter.dart'; | ||
| 11 | 7 | ||
| 12 | import '../../routers/fluro_navigator.dart'; | 8 | import '../../routers/fluro_navigator.dart'; |
| 13 | import '../../util/toast_utils.dart'; | 9 | import '../../util/toast_utils.dart'; |
| ... | @@ -20,12 +16,11 @@ class AddressSelectPage extends StatefulWidget { | ... | @@ -20,12 +16,11 @@ class AddressSelectPage extends StatefulWidget { |
| 20 | } | 16 | } |
| 21 | 17 | ||
| 22 | class AddressSelectPageState extends State<AddressSelectPage> { | 18 | class AddressSelectPageState extends State<AddressSelectPage> { |
| 23 | - List<BMFSuggestionInfo> _list = []; | 19 | + // List<BMFSuggestionInfo> _list = []; |
| 24 | int _index = 0; | 20 | int _index = 0; |
| 25 | final ScrollController _controller = ScrollController(); | 21 | final ScrollController _controller = ScrollController(); |
| 26 | - late BMFMapController _myMapController; | 22 | + LatLng _center = const LatLng(45.521563, -122.677433); |
| 27 | - BaiduLocation _locationResult = BaiduLocation(); | 23 | + late GoogleMapController mapController; |
| 28 | - LocationFlutterPlugin myLocPlugin = LocationFlutterPlugin(); | ||
| 29 | bool isLoading = false; | 24 | bool isLoading = false; |
| 30 | 25 | ||
| 31 | @override | 26 | @override |
| ... | @@ -37,138 +32,39 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -37,138 +32,39 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 37 | @override | 32 | @override |
| 38 | void initState() { | 33 | void initState() { |
| 39 | super.initState(); | 34 | super.initState(); |
| 40 | - myLocPlugin.setAgreePrivacy(true); | 35 | + _getCurrentLocation(); |
| 41 | - // 百度地图sdk初始化鉴权 | ||
| 42 | - if (Platform.isIOS) { | ||
| 43 | - myLocPlugin.authAK('rMsgMvYERM9zHDDdaipk34oBx7yoaGQh'); | ||
| 44 | - BMFMapSDK.setApiKeyAndCoordType( | ||
| 45 | - 'rMsgMvYERM9zHDDdaipk34oBx7yoaGQh', BMF_COORD_TYPE.BD09LL); | ||
| 46 | - | ||
| 47 | - ///接受定位回调 | ||
| 48 | - myLocPlugin.singleLocationCallback(callback: (BaiduLocation result) { | ||
| 49 | - setState(() { | ||
| 50 | - _locationResult = result; | ||
| 51 | - locationFinish(); | ||
| 52 | - }); | ||
| 53 | - }); | ||
| 54 | - } else if (Platform.isAndroid) { | ||
| 55 | - // Android 目前不支持接口设置Apikey, | ||
| 56 | - // 请在主工程的Manifest文件里设置,详细配置方法请参考官网(https://lbsyun.baidu.com/)demo | ||
| 57 | - BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); | ||
| 58 | - myLocPlugin.seriesLocationCallback(callback: (BaiduLocation result) { | ||
| 59 | - setState(() { | ||
| 60 | - _locationResult = result; | ||
| 61 | - | ||
| 62 | - locationFinish(); | ||
| 63 | - myLocPlugin.stopLocation(); | ||
| 64 | - }); | ||
| 65 | - }); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - ///设置定位参数 | ||
| 69 | - _locationAction(); | ||
| 70 | - _startLocation(); | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - void _locationAction() async { | ||
| 74 | - Map iosMap = initIOSOptions().getMap(); | ||
| 75 | - Map androidMap = initAndroidOptions().getMap(); | ||
| 76 | - | ||
| 77 | - await myLocPlugin.prepareLoc(androidMap, iosMap); | ||
| 78 | } | 36 | } |
| 79 | 37 | ||
| 80 | - ///定位完成添加mark | 38 | + Future<void> _getCurrentLocation() async { |
| 81 | - Future<void> locationFinish() async { | 39 | + Location location = Location(); |
| 82 | - /// 创建BMFMarker | ||
| 83 | - BMFMarker marker = BMFMarker.icon( | ||
| 84 | - position: BMFCoordinate( | ||
| 85 | - _locationResult.latitude ?? 0.0, _locationResult.longitude ?? 0.0), | ||
| 86 | - title: 'flutterMaker', | ||
| 87 | - identifier: 'flutter_marker', | ||
| 88 | - icon: 'assets/images/map/icon_mark.png'); | ||
| 89 | - | ||
| 90 | - /// 添加Marker | ||
| 91 | - _myMapController.addMarker(marker); | ||
| 92 | 40 | ||
| 93 | - ///设置中心点 | 41 | + bool serviceEnabled; |
| 94 | - _myMapController.setCenterCoordinate( | 42 | + PermissionStatus permissionGranted; |
| 95 | - BMFCoordinate( | ||
| 96 | - _locationResult.latitude ?? 0.0, _locationResult.longitude ?? 0.0), | ||
| 97 | - false); | ||
| 98 | 43 | ||
| 99 | - // 构造检索参数 | 44 | + serviceEnabled = await location.serviceEnabled(); |
| 100 | - BMFSuggestionSearchOption suggestionSearchOption = | 45 | + if (!serviceEnabled) { |
| 101 | - BMFSuggestionSearchOption( | 46 | + serviceEnabled = await location.requestService(); |
| 102 | - keyword: '街道', | 47 | + if (!serviceEnabled) { |
| 103 | - cityname: _locationResult.city, | 48 | + return; |
| 104 | - location: | ||
| 105 | - BMFCoordinate(_locationResult.latitude!, _locationResult.longitude!), | ||
| 106 | - cityLimit: true, | ||
| 107 | - ); | ||
| 108 | - BMFSuggestionSearch suggestionSearch = BMFSuggestionSearch(); | ||
| 109 | - suggestionSearch.onGetSuggestSearchResult(callback: | ||
| 110 | - (BMFSuggestionSearchResult result, BMFSearchErrorCode errorCode) { | ||
| 111 | - print("sug检索回调 result = ${result.toMap()} \n errorCode = ${errorCode}"); | ||
| 112 | - _list = result.suggestionList!; | ||
| 113 | - if (_list.isEmpty) { | ||
| 114 | - Toast.show("暂时无法搜索到该位置!"); | ||
| 115 | } | 49 | } |
| 116 | - isLoading = false; | ||
| 117 | - setState(() {}); | ||
| 118 | - }); | ||
| 119 | - bool flag = await suggestionSearch.suggestionSearch(suggestionSearchOption); | ||
| 120 | - } | ||
| 121 | - | ||
| 122 | - /// 设置地图参数 | ||
| 123 | - BaiduLocationAndroidOption initAndroidOptions() { | ||
| 124 | - BaiduLocationAndroidOption options = BaiduLocationAndroidOption( | ||
| 125 | - coorType: 'bd09ll', | ||
| 126 | - locationMode: BMFLocationMode.hightAccuracy, | ||
| 127 | - isNeedAddress: true, | ||
| 128 | - isNeedAltitude: true, | ||
| 129 | - isNeedLocationPoiList: true, | ||
| 130 | - isNeedNewVersionRgc: true, | ||
| 131 | - isNeedLocationDescribe: true, | ||
| 132 | - openGps: true, | ||
| 133 | - locationPurpose: BMFLocationPurpose.sport, | ||
| 134 | - coordType: BMFLocationCoordType.bd09ll); | ||
| 135 | - return options; | ||
| 136 | - } | ||
| 137 | - | ||
| 138 | - BaiduLocationIOSOption initIOSOptions() { | ||
| 139 | - BaiduLocationIOSOption options = BaiduLocationIOSOption( | ||
| 140 | - coordType: BMFLocationCoordType.bd09ll, | ||
| 141 | - BMKLocationCoordinateType: 'BMKLocationCoordinateTypeBMK09LL', | ||
| 142 | - desiredAccuracy: BMFDesiredAccuracy.best); | ||
| 143 | - return options; | ||
| 144 | - } | ||
| 145 | - | ||
| 146 | - /// 启动定位 | ||
| 147 | - Future<void> _startLocation() async { | ||
| 148 | - isLoading = true; | ||
| 149 | - if (Platform.isIOS) { | ||
| 150 | - await myLocPlugin | ||
| 151 | - .singleLocation({'isReGeocode': true, 'isNetworkState': true}); | ||
| 152 | - } else if (Platform.isAndroid) { | ||
| 153 | - await myLocPlugin.startLocation(); | ||
| 154 | } | 50 | } |
| 155 | - } | ||
| 156 | 51 | ||
| 157 | - /// 创建完成回调 | 52 | + permissionGranted = await location.hasPermission(); |
| 158 | - void onBMFMapCreated(BMFMapController controller) { | 53 | + if (permissionGranted == PermissionStatus.denied) { |
| 159 | - _myMapController = controller; | 54 | + permissionGranted = await location.requestPermission(); |
| 55 | + if (permissionGranted != PermissionStatus.granted) { | ||
| 56 | + return; | ||
| 57 | + } | ||
| 58 | + } | ||
| 160 | 59 | ||
| 161 | - /// 地图加载回调 | 60 | + location.onLocationChanged.listen((LocationData currentLocation) { |
| 162 | - _myMapController.setMapDidLoadCallback(callback: () {}); | 61 | + // _center = LatLng(currentLocation.latitude!, currentLocation.longitude!); |
| 62 | + setState(() {}); | ||
| 63 | + }); | ||
| 163 | } | 64 | } |
| 164 | 65 | ||
| 165 | - /// 设置地图参数 | 66 | + void _onMapCreated(GoogleMapController controller) { |
| 166 | - BMFMapOptions initMapOptions() { | 67 | + mapController = controller; |
| 167 | - BMFMapOptions mapOptions = BMFMapOptions( | ||
| 168 | - center: BMFCoordinate(39.917215, 116.380341), | ||
| 169 | - zoomLevel: 18, | ||
| 170 | - ); | ||
| 171 | - return mapOptions; | ||
| 172 | } | 68 | } |
| 173 | 69 | ||
| 174 | @override | 70 | @override |
| ... | @@ -183,28 +79,6 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -183,28 +79,6 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 183 | duration: const Duration(milliseconds: 10), curve: Curves.ease); | 79 | duration: const Duration(milliseconds: 10), curve: Curves.ease); |
| 184 | _index = 0; | 80 | _index = 0; |
| 185 | // 构造检索参数 | 81 | // 构造检索参数 |
| 186 | - BMFSuggestionSearchOption suggestionSearchOption = | ||
| 187 | - BMFSuggestionSearchOption( | ||
| 188 | - keyword: text, | ||
| 189 | - cityname: _locationResult.city, | ||
| 190 | - location: BMFCoordinate( | ||
| 191 | - _locationResult.latitude!, _locationResult.longitude!), | ||
| 192 | - cityLimit: true, | ||
| 193 | - ); | ||
| 194 | - BMFSuggestionSearch suggestionSearch = BMFSuggestionSearch(); | ||
| 195 | - suggestionSearch.onGetSuggestSearchResult(callback: | ||
| 196 | - (BMFSuggestionSearchResult result, BMFSearchErrorCode errorCode) { | ||
| 197 | - print( | ||
| 198 | - "sug检索回调 result = ${result.toMap()} \n errorCode = ${errorCode}"); | ||
| 199 | - _list = result.suggestionList!; | ||
| 200 | - if (_list.isEmpty) { | ||
| 201 | - Toast.show("暂时无法搜索到该位置!"); | ||
| 202 | - } | ||
| 203 | - isLoading = false; | ||
| 204 | - setState(() {}); | ||
| 205 | - }); | ||
| 206 | - bool flag = | ||
| 207 | - await suggestionSearch.suggestionSearch(suggestionSearchOption); | ||
| 208 | }, | 82 | }, |
| 209 | ), | 83 | ), |
| 210 | body: SafeArea( | 84 | body: SafeArea( |
| ... | @@ -212,11 +86,12 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -212,11 +86,12 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 212 | children: <Widget>[ | 86 | children: <Widget>[ |
| 213 | Expanded( | 87 | Expanded( |
| 214 | flex: 9, | 88 | flex: 9, |
| 215 | - child: BMFMapWidget( | 89 | + child: GoogleMap( |
| 216 | - onBMFMapCreated: (BMFMapController controller) { | 90 | + onMapCreated: _onMapCreated, |
| 217 | - onBMFMapCreated(controller); | 91 | + initialCameraPosition: CameraPosition( |
| 218 | - }, | 92 | + target: _center, |
| 219 | - mapOptions: initMapOptions(), | 93 | + zoom: 11.0, |
| 94 | + ), | ||
| 220 | ), | 95 | ), |
| 221 | ), | 96 | ), |
| 222 | Expanded( | 97 | Expanded( |
| ... | @@ -224,38 +99,14 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -224,38 +99,14 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 224 | child: isLoading | 99 | child: isLoading |
| 225 | ? const GFLoader() | 100 | ? const GFLoader() |
| 226 | : ListView.separated( | 101 | : ListView.separated( |
| 227 | - controller: _controller, | 102 | + controller: _controller, |
| 228 | - itemCount: _list.length, | 103 | + itemCount: 1, |
| 229 | separatorBuilder: (_, index) => const Divider(), | 104 | separatorBuilder: (_, index) => const Divider(), |
| 230 | itemBuilder: (_, index) { | 105 | itemBuilder: (_, index) { |
| 231 | return _AddressItem( | 106 | return _AddressItem( |
| 232 | isSelected: _index == index, | 107 | isSelected: _index == index, |
| 233 | - poi: _list[index], | ||
| 234 | onTap: () { | 108 | onTap: () { |
| 235 | _index = index; | 109 | _index = index; |
| 236 | - _myMapController.updateMapOptions(BMFMapOptions( | ||
| 237 | - center: BMFCoordinate( | ||
| 238 | - _list[index].location!.latitude, | ||
| 239 | - _list[index].location!.longitude))); | ||
| 240 | - | ||
| 241 | - /// 创建BMFMarker | ||
| 242 | - BMFMarker marker = BMFMarker.icon( | ||
| 243 | - position: BMFCoordinate( | ||
| 244 | - _list[index].location!.latitude, | ||
| 245 | - _list[index].location!.longitude), | ||
| 246 | - title: 'flutterMaker', | ||
| 247 | - identifier: 'flutter_marker', | ||
| 248 | - icon: 'assets/images/map/icon_mark.png'); | ||
| 249 | - | ||
| 250 | - /// 添加Marker | ||
| 251 | - _myMapController.addMarker(marker); | ||
| 252 | - | ||
| 253 | - ///设置中心点 | ||
| 254 | - _myMapController.setCenterCoordinate( | ||
| 255 | - BMFCoordinate(_list[index].location!.latitude, | ||
| 256 | - _list[index].location!.longitude), | ||
| 257 | - false); | ||
| 258 | - | ||
| 259 | setState(() {}); | 110 | setState(() {}); |
| 260 | }, | 111 | }, |
| 261 | ); | 112 | ); |
| ... | @@ -264,11 +115,11 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -264,11 +115,11 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 264 | ), | 115 | ), |
| 265 | MyButton( | 116 | MyButton( |
| 266 | onPressed: () { | 117 | onPressed: () { |
| 267 | - if (_list.isEmpty) { | 118 | + // if (_list.isEmpty) { |
| 268 | - Toast.show('未选择地址!'); | 119 | + // Toast.show('未选择地址!'); |
| 269 | - return; | 120 | + // return; |
| 270 | - } | 121 | + // } |
| 271 | - NavigatorUtils.goBackWithParams(context, _list[_index]); | 122 | + // NavigatorUtils.goBackWithParams(context, _list[_index]); |
| 272 | }, | 123 | }, |
| 273 | text: '确认选择地址', | 124 | text: '确认选择地址', |
| 274 | ) | 125 | ) |
| ... | @@ -282,12 +133,11 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -282,12 +133,11 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 282 | class _AddressItem extends StatelessWidget { | 133 | class _AddressItem extends StatelessWidget { |
| 283 | const _AddressItem({ | 134 | const _AddressItem({ |
| 284 | Key? key, | 135 | Key? key, |
| 285 | - required this.poi, | ||
| 286 | this.isSelected = false, | 136 | this.isSelected = false, |
| 287 | this.onTap, | 137 | this.onTap, |
| 288 | }) : super(key: key); | 138 | }) : super(key: key); |
| 289 | 139 | ||
| 290 | - final BMFSuggestionInfo poi; | 140 | + // final BMFSuggestionInfo poi; |
| 291 | final bool isSelected; | 141 | final bool isSelected; |
| 292 | final GestureTapCallback? onTap; | 142 | final GestureTapCallback? onTap; |
| 293 | 143 | ||
| ... | @@ -303,7 +153,7 @@ class _AddressItem extends StatelessWidget { | ... | @@ -303,7 +153,7 @@ class _AddressItem extends StatelessWidget { |
| 303 | children: <Widget>[ | 153 | children: <Widget>[ |
| 304 | Expanded( | 154 | Expanded( |
| 305 | child: Text( | 155 | child: Text( |
| 306 | - '${poi.city} ${poi.district} ${poi.address}', | 156 | + '', // '${poi.city} ${poi.district} ${poi.address}', |
| 307 | ), | 157 | ), |
| 308 | ), | 158 | ), |
| 309 | Visibility( | 159 | Visibility( | ... | ... |
| ... | @@ -391,34 +391,6 @@ packages: | ... | @@ -391,34 +391,6 @@ 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_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: | ||
| 402 | - dependency: "direct main" | ||
| 403 | - description: | ||
| 404 | - name: flutter_baidu_mapapi_map | ||
| 405 | - url: "https://pub.flutter-io.cn" | ||
| 406 | - source: hosted | ||
| 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" | ||
| 422 | flutter_blurhash: | 394 | flutter_blurhash: |
| 423 | dependency: transitive | 395 | dependency: transitive |
| 424 | description: | 396 | description: |
| ... | @@ -426,13 +398,6 @@ packages: | ... | @@ -426,13 +398,6 @@ packages: |
| 426 | url: "https://pub.flutter-io.cn" | 398 | url: "https://pub.flutter-io.cn" |
| 427 | source: hosted | 399 | source: hosted |
| 428 | version: "0.7.0" | 400 | version: "0.7.0" |
| 429 | - flutter_bmflocation: | ||
| 430 | - dependency: "direct main" | ||
| 431 | - description: | ||
| 432 | - name: flutter_bmflocation | ||
| 433 | - url: "https://pub.flutter-io.cn" | ||
| 434 | - source: hosted | ||
| 435 | - version: "3.2.0" | ||
| 436 | flutter_cache_manager: | 401 | flutter_cache_manager: |
| 437 | dependency: transitive | 402 | dependency: transitive |
| 438 | description: | 403 | description: |
| ... | @@ -612,6 +577,20 @@ packages: | ... | @@ -612,6 +577,20 @@ packages: |
| 612 | url: "https://pub.flutter-io.cn" | 577 | url: "https://pub.flutter-io.cn" |
| 613 | source: hosted | 578 | source: hosted |
| 614 | version: "3.0.1" | 579 | version: "3.0.1" |
| 580 | + google_maps_flutter: | ||
| 581 | + dependency: "direct main" | ||
| 582 | + description: | ||
| 583 | + name: google_maps_flutter | ||
| 584 | + url: "https://pub.flutter-io.cn" | ||
| 585 | + source: hosted | ||
| 586 | + version: "2.1.10" | ||
| 587 | + google_maps_flutter_platform_interface: | ||
| 588 | + dependency: transitive | ||
| 589 | + description: | ||
| 590 | + name: google_maps_flutter_platform_interface | ||
| 591 | + url: "https://pub.flutter-io.cn" | ||
| 592 | + source: hosted | ||
| 593 | + version: "2.2.2" | ||
| 615 | graphs: | 594 | graphs: |
| 616 | dependency: transitive | 595 | dependency: transitive |
| 617 | description: | 596 | description: |
| ... | @@ -785,6 +764,27 @@ packages: | ... | @@ -785,6 +764,27 @@ packages: |
| 785 | url: "https://pub.flutter-io.cn" | 764 | url: "https://pub.flutter-io.cn" |
| 786 | source: hosted | 765 | source: hosted |
| 787 | version: "2.0.0" | 766 | version: "2.0.0" |
| 767 | + location: | ||
| 768 | + dependency: "direct main" | ||
| 769 | + description: | ||
| 770 | + name: location | ||
| 771 | + url: "https://pub.flutter-io.cn" | ||
| 772 | + source: hosted | ||
| 773 | + version: "4.4.0" | ||
| 774 | + location_platform_interface: | ||
| 775 | + dependency: transitive | ||
| 776 | + description: | ||
| 777 | + name: location_platform_interface | ||
| 778 | + url: "https://pub.flutter-io.cn" | ||
| 779 | + source: hosted | ||
| 780 | + version: "2.3.0" | ||
| 781 | + location_web: | ||
| 782 | + dependency: transitive | ||
| 783 | + description: | ||
| 784 | + name: location_web | ||
| 785 | + url: "https://pub.flutter-io.cn" | ||
| 786 | + source: hosted | ||
| 787 | + version: "3.1.1" | ||
| 788 | logger: | 788 | logger: |
| 789 | dependency: transitive | 789 | dependency: transitive |
| 790 | description: | 790 | description: | ... | ... |
| ... | @@ -124,10 +124,8 @@ dependencies: | ... | @@ -124,10 +124,8 @@ dependencies: |
| 124 | 124 | ||
| 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 | + location: ^4.4.0 |
| 128 | - flutter_baidu_mapapi_utils: ^3.2.0 | 128 | + google_maps_flutter: ^2.1.10 |
| 129 | - flutter_baidu_mapapi_search: ^3.2.0 | ||
| 130 | - flutter_bmflocation: ^3.2.0 | ||
| 131 | 129 | ||
| 132 | dependency_overrides: | 130 | dependency_overrides: |
| 133 | decimal: 1.5.0 | 131 | decimal: 1.5.0 | ... | ... |
-
Please register or login to post a comment