diff --git a/assets/image/2x/icon_map_marker.png b/assets/image/2x/icon_map_marker.png index ab786207..01d25319 100644 Binary files a/assets/image/2x/icon_map_marker.png and b/assets/image/2x/icon_map_marker.png differ diff --git a/assets/image/icon_map_marker.png b/assets/image/icon_map_marker.png index aebf1433..01d25319 100644 Binary files a/assets/image/icon_map_marker.png and b/assets/image/icon_map_marker.png differ diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 85bfaa51..32522f2a 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -6,6 +6,7 @@ PODS: - BaiduMapKit/Base - BaiduMapKit/Utils (6.2.0): - BaiduMapKit/Base + - BMKLocationKit (2.0.0) - Flutter (1.0.0) - flutter_baidu_mapapi_base (2.0.0): - BaiduMapKit/Utils (= 6.2.0) @@ -22,6 +23,9 @@ PODS: - BaiduMapKit/Utils (= 6.2.0) - Flutter - flutter_baidu_mapapi_base + - flutter_bmflocation (1.0.3): + - BMKLocationKit + - Flutter - fluwx (0.0.1): - Flutter - WechatOpenSDK (= 1.8.7.1) @@ -98,6 +102,7 @@ DEPENDENCIES: - flutter_baidu_mapapi_map (from `.symlinks/plugins/flutter_baidu_mapapi_map/ios`) - flutter_baidu_mapapi_search (from `.symlinks/plugins/flutter_baidu_mapapi_search/ios`) - flutter_baidu_mapapi_utils (from `.symlinks/plugins/flutter_baidu_mapapi_utils/ios`) + - flutter_bmflocation (from `.symlinks/plugins/flutter_bmflocation/ios`) - fluwx (from `.symlinks/plugins/fluwx/ios`) - image_cropper (from `.symlinks/plugins/image_cropper/ios`) - image_picker (from `.symlinks/plugins/image_picker/ios`) @@ -116,6 +121,7 @@ DEPENDENCIES: SPEC REPOS: trunk: - BaiduMapKit + - BMKLocationKit - FMDB - mob_sharesdk - MOBFoundation @@ -134,6 +140,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/flutter_baidu_mapapi_search/ios" flutter_baidu_mapapi_utils: :path: ".symlinks/plugins/flutter_baidu_mapapi_utils/ios" + flutter_bmflocation: + :path: ".symlinks/plugins/flutter_bmflocation/ios" fluwx: :path: ".symlinks/plugins/fluwx/ios" image_cropper: @@ -165,11 +173,13 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: BaiduMapKit: 907c6d9b74f66c3ff4741fc4b568ae0b339917f8 + BMKLocationKit: 097814ef672b1e57e86e6c1968d7892fb78002bf Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c flutter_baidu_mapapi_base: 90fddba11ec4435406a7211d6ee905b4311c31db flutter_baidu_mapapi_map: 771bf00671832b1fcddb17733518cd631529df16 flutter_baidu_mapapi_search: 4cffaa74e739a4114595c4f82f790e1783bb612d flutter_baidu_mapapi_utils: a5bd582b91ecd35be1bc45558b38f49d5684f70a + flutter_bmflocation: 12f1ba91bae4b16d78d4f475023e0254ed351f1c fluwx: 07a55ed66bf3a4961e836a2a411b02dcada32902 FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a image_cropper: f1668dd8d2cad2d357955caad15a40547856edcb diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 7c2efa0a..fe5c3c7e 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0558860326BD10CA00FB1CFE /* test.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0558860226BD10CA00FB1CFE /* test.swift */; }; 05C5426026BB9CEB00D26AC2 /* liblibIO.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EE8F33A2695816000237A5E /* liblibIO.a */; }; 05C5426F26BBE8FE00D26AC2 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EE8F373269581F600237A5E /* CoreLocation.framework */; }; 05C5427126BBE93600D26AC2 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 05C5427026BBE93600D26AC2 /* AdSupport.framework */; }; @@ -68,7 +69,7 @@ 89AEFA9126A69A2200DD2817 /* ExternalAccessory.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 89AEFA9026A69A2200DD2817 /* ExternalAccessory.framework */; }; 89AEFA9326A69A3600DD2817 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 89AEFA9226A69A3600DD2817 /* Security.framework */; }; 89AEFA9526A69A4800DD2817 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 89AEFA9426A69A4800DD2817 /* SystemConfiguration.framework */; }; - 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; + 978B8F6F1D3862AE00F588F7 /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.mm */; }; 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; @@ -90,6 +91,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 0558860226BD10CA00FB1CFE /* test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = test.swift; sourceTree = ""; }; 05C5427026BBE93600D26AC2 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; }; 05C5427326BCE3AC00D26AC2 /* BMKLocationKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = BMKLocationKit.framework; sourceTree = ""; }; 05C5427526BCFA9000D26AC2 /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; }; @@ -211,7 +213,7 @@ 6EE8F37E269582C200237A5E /* UniappPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UniappPlugin.m; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AppDelegate.mm; sourceTree = ""; }; 81880E8F5E90EA6E5E0D57EB /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 89847A4826A14482008C8077 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = ""; }; 899C4C3826A5171500B44087 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = ""; }; @@ -591,7 +593,7 @@ 6EE8F2E42695813500237A5E /* UniMPSDK */, 6EE8F2E32695806400237A5E /* Class */, 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, - 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.mm */, 97C146FA1CF9000F007C117D /* Main.storyboard */, 97C146FD1CF9000F007C117D /* Assets.xcassets */, 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, @@ -600,6 +602,7 @@ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 05C5427726BCFCBB00D26AC2 /* Runner-Bridging-Header.h */, + 0558860226BD10CA00FB1CFE /* test.swift */, ); path = Runner; sourceTree = ""; @@ -769,9 +772,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, + 978B8F6F1D3862AE00F588F7 /* AppDelegate.mm in Sources */, 6EE8F37F269582C200237A5E /* UniappPlugin.m in Sources */, 97C146F31CF9000F007C117D /* main.m in Sources */, + 0558860326BD10CA00FB1CFE /* test.swift in Sources */, 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -878,7 +882,7 @@ "$(inherited)", "$(PROJECT_DIR)/UniMPSDK/Libs", ); - GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; + GCC_INPUT_FILETYPE = automatic; HEADER_SEARCH_PATHS = ( "$(inherited)", "\"${PODS_ROOT}/Headers/Public\"", @@ -1104,7 +1108,7 @@ "$(inherited)", "$(PROJECT_DIR)/UniMPSDK/Libs", ); - GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; + GCC_INPUT_FILETYPE = automatic; HEADER_SEARCH_PATHS = ( "$(inherited)", "\"${PODS_ROOT}/Headers/Public\"", @@ -1223,7 +1227,7 @@ "$(inherited)", "$(PROJECT_DIR)/UniMPSDK/Libs", ); - GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; + GCC_INPUT_FILETYPE = automatic; HEADER_SEARCH_PATHS = ( "$(inherited)", "\"${PODS_ROOT}/Headers/Public\"", diff --git a/ios/Runner/AppDelegate.m b/ios/Runner/AppDelegate.mm similarity index 100% rename from ios/Runner/AppDelegate.m rename to ios/Runner/AppDelegate.mm diff --git a/ios/Runner/test.swift b/ios/Runner/test.swift new file mode 100644 index 00000000..bd164721 --- /dev/null +++ b/ios/Runner/test.swift @@ -0,0 +1,12 @@ +// +// test.swift +// Runner +// +// Created by f on 2021/8/6. +// + +import UIKit + +class test: NSObject { + +} diff --git a/lib/address/address_map_page.dart b/lib/address/address_map_page.dart index c59d8a94..d2381ecf 100644 --- a/lib/address/address_map_page.dart +++ b/lib/address/address_map_page.dart @@ -9,7 +9,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; +import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; +import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; +import 'package:flutter_bmflocation/flutter_baidu_location_android_option.dart'; +import 'package:flutter_bmflocation/flutter_baidu_location_ios_option.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/address.dart'; @@ -27,7 +31,6 @@ class AddressMapPage extends StatefulWidget { } class _AddressMapPage extends State { - //加载自定义地图样式 void _loadCustomData() async { setState(() { @@ -57,7 +60,6 @@ class _AddressMapPage extends State { }); if (aMapFlutterLocation == null) { - aMapFlutterLocation = LocationFlutterPlugin(); aMapFlutterLocation.onResultCallback().listen((event) { print("event: ${jsonEncode(event)}"); @@ -72,72 +74,113 @@ class _AddressMapPage extends State { } else { latLng = BMFCoordinate(event["latitude"], event["longitude"]); } - saveLatLng(latLng); - if (_mapController != null) - _mapController.updateMapOptions( - BMFMapOptions( - center: latLng, - zoomLevel: 15, - ), - ); - searchPoi(latLng); + BMFCalculateUtils.coordConvert( + coordinate: latLng, + fromType: BMF_COORD_TYPE.COMMON, + toType: BMF_COORD_TYPE.BD09LL) + .then((value) { + saveLatLng(value); + if (_mapController != null) { + this.latLng = value; + addMarker(); + _mapController.updateMapOptions( + BMFMapOptions( + center: latLng, + zoomLevel: 15, + ), + ); + } + searchPoi(latLng); + }); } }); } - aMapFlutterLocation.prepareLoc({ - "coorType": "bd09ll", - "isNeedAddres": false, - "isNeedAltitude": false, - "isNeedLocationPoiList": false, - "isNeedLocationDescribe": false, - "isNeedNewVersionRgc": false, - "scanspan": 0, - "openGps": true, - "locationMode": 2, - }, { - "locationMode": "kCLLocationAccuracyBest", - "locationTimeout": 10, - "reGeocodeTimeout": 10, - "activityType": "CLActivityTypeAutomotiveNavigation", - "BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL", - "BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL", - "isNeedNewVersionRgc": false, - }); - - _loadCustomData(); + _setLocOption(); getLatLng(); startLocation(); } + /// 设置android端和ios端定位参数 + void _setLocOption() { + /// android 端设置定位参数 + BaiduLocationAndroidOption androidOption = new BaiduLocationAndroidOption(); + androidOption.setCoorType("GCJ02"); // 设置返回的位置坐标系类型 + androidOption.setIsNeedAltitude(true); // 设置是否需要返回海拔高度信息 + androidOption.setIsNeedAddres(true); // 设置是否需要返回地址信息 + androidOption.setIsNeedLocationPoiList(true); // 设置是否需要返回周边poi信息 + androidOption.setIsNeedNewVersionRgc(true); // 设置是否需要返回最新版本rgc信息 + androidOption.setIsNeedLocationDescribe(true); // 设置是否需要返回位置描述 + androidOption.setOpenGps(true); // 设置是否需要使用gps + androidOption.setLocationMode(LocationMode.Hight_Accuracy); // 设置定位模式 + androidOption.setScanspan(0); // 设置发起定位请求时间间隔 + + Map androidMap = androidOption.getMap(); + + /// ios 端设置定位参数 + BaiduLocationIOSOption iosOption = new BaiduLocationIOSOption(); + iosOption.setIsNeedNewVersionRgc(true); // 设置是否需要返回最新版本rgc信息 + iosOption.setBMKLocationCoordinateType( + "BMKLocationCoordinateTypeGCJ02"); // 设置返回的位置坐标系类型 + iosOption.setActivityType("CLActivityTypeAutomotiveNavigation"); // 设置应用位置类型 + iosOption.setLocationTimeout(10); // 设置位置获取超时时间 + iosOption.setDesiredAccuracy("kCLLocationAccuracyBest"); // 设置预期精度参数 + iosOption.setReGeocodeTimeout(10); // 设置获取地址信息超时时间 + iosOption.setDistanceFilter(1000); // 设置定位最小更新距离 + iosOption.setAllowsBackgroundLocationUpdates(true); // 是否允许后台定位 + iosOption.setPauseLocUpdateAutomatically(true); // 定位是否会被系统自动暂停 + + Map iosMap = iosOption.getMap(); + + aMapFlutterLocation.prepareLoc(androidMap, iosMap); + } + List
poiList; searchPoi(BMFCoordinate latLng) async { keyWord = textEditingController.text; - var addressPoi = await apiService.searchPoi( - "${latLng.latitude}", "${latLng.longitude}", keyWord, 20, 1); - List poi = addressPoi['pois']; - poiList = poi - .map((e) => Address.fromJson({ - "address": e["address"] is List ? "" : e["address"], - "area": e["adname"], - "city": e["cityname"], - "province": e["pname"], - "latitude": e["location"].toString().split(",")[0], - "longitude": e["location"].toString().split(",")[1], - "cityInfo": e["name"], - "id": "", - "mid": "", - "phone": "", - "tag": "", - "username": "", - "isDefault": true, - })) - .toList(); - setState(() {}); + + BMFPoiNearbySearch bmfPoiNearbySearch = BMFPoiNearbySearch(); + bmfPoiNearbySearch.onGetPoiNearbySearchResult( + callback: (BMFPoiSearchResult result, BMFSearchErrorCode errorCode) { + if ((DateTime.now().millisecondsSinceEpoch - time) > 2000) { + result.poiInfoList.map((e) => print("sssssssssss:${e.toMap()}")); + poiList = result.poiInfoList + .map((e) => Address.fromJson({ + "address": e.address, + "area": e.name, + "city": e.city, + "province": e.province, + "latitude": e.pt.latitude, + "longitude": e.pt.longitude, + "cityInfo": e.name, + "id": "", + "mid": "", + "phone": "", + "tag": "", + "username": "", + "isDefault": true, + })) + .toList(); + print("object112221: ${poiList.length}"); + setState(() { + time = DateTime.now().millisecondsSinceEpoch; + }); + } + }); + bmfPoiNearbySearch.poiNearbySearch(BMFPoiNearbySearchOption( + keywords: ["all"], + radius: 100000, + location: latLng, + pageSize: 20, + pageIndex: 0, + isRadiusLimit: true, + )); } + int time = 0; + startLocation() async { if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) { enableLocation(); @@ -173,7 +216,7 @@ class _AddressMapPage extends State { S.of(context).nindingweigongnengweikaiqi, S.of(context).weilexiangnintuijianfujindemendianxinxi, S.of(context).dakaidingwei, - (result) async { + (result) async { if (result) { final AndroidIntent intent = AndroidIntent( action: 'action_location_source_settings', @@ -197,7 +240,7 @@ class _AddressMapPage extends State { S.of(context).nindingweiquanxianweiyunxu, S.of(context).weilexiangnintuijianfujindemendianxinxi, S.of(context).kaiqiquanxian, - (result) async { + (result) async { if (result) { await openAppSettings(); if (await Permission.location.isGranted) { @@ -213,11 +256,47 @@ class _AddressMapPage extends State { BMFMapController _mapController; void onMapCreated(BMFMapController controller) { + controller.setMapRegionDidChangeCallback(callback: (status) { + center = status.targetGeoPt; + searchPoi(center); + }); + setState(() { _mapController = controller; + _mapController.showUserLocation(true); + + _loadCustomData(); + addMarker(); }); } + BMFCoordinate latLng; + BMFMarker bmfMarker; + + addMarker() { + if (latLng == null) return; + if (bmfMarker == null && _mapController != null) { + print("map_wid: ${MediaQuery.of(context).size.width}"); + print("map_hei: ${MediaQuery.of(context).size.height}"); + + bmfMarker = BMFMarker( + position: latLng, + screenPointToLock: BMFPoint(MediaQuery.of(context).size.width / 2, + MediaQuery.of(context).size.height / 4), + isLockedToScreen: true, + centerOffset: BMFPoint(0.5, 0.9), + enabled: false, + icon: "assets/image/icon_map_marker.png", + draggable: false, + ); + _mapController.addMarker(bmfMarker); + } + bmfMarker.updateIsLockedToScreen( + true, + BMFPoint(MediaQuery.of(context).size.width / 2, + MediaQuery.of(context).size.height / 4)); + } + saveLatLng(BMFCoordinate latLng) async { SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.setString("latitude", "${latLng.latitude}"); @@ -231,8 +310,9 @@ class _AddressMapPage extends State { _mapController.updateMapOptions( BMFMapOptions( center: BMFCoordinate( - double.tryParse(value.getString("latitude")), - double.tryParse(value.getString("longitude"))), + double.tryParse(value.getString("latitude")), + double.tryParse(value.getString("longitude")), + ), zoomLevel: 15, ), ); @@ -277,18 +357,18 @@ class _AddressMapPage extends State { // ].toSet(), ), ), - Center( - child: IgnorePointer( - child: Container( - margin: EdgeInsets.only(bottom: 44.h), - child: Image.asset( - "assets/image/icon_address_location.png", - width: 66.w, - height: 75.h, - ), - ), - ), - ), + // Center( + // child: IgnorePointer( + // child: Container( + // margin: EdgeInsets.only(bottom: 44.h), + // child: Image.asset( + // "assets/image/icon_address_location.png", + // width: 66.w, + // height: 75.h, + // ), + // ), + // ), + // ), searchWidget(), Positioned( right: 17, @@ -372,7 +452,7 @@ class _AddressMapPage extends State { color: Color(0xFF4C4C4C), fontSize: 14.sp, ), - ) + ), ], ), ); @@ -386,16 +466,17 @@ class _AddressMapPage extends State { margin: EdgeInsets.fromLTRB(16, 48, 16, 8), padding: EdgeInsets.fromLTRB(10, 6, 16, 6), decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(4)), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(12), - offset: Offset(0, 3), - blurRadius: 14, - spreadRadius: 0, - ) - ]), + color: Colors.white, + borderRadius: BorderRadius.all(Radius.circular(4)), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(12), + offset: Offset(0, 3), + blurRadius: 14, + spreadRadius: 0, + ) + ], + ), child: Row( mainAxisSize: MainAxisSize.max, children: [ diff --git a/lib/main.dart b/lib/main.dart index 091f68a7..ebed8b0e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -121,7 +121,7 @@ initSdk() async { BMFMapSDK.setApiKeyAndCoordType( '7IACaFNxOX2EMauupIZisjI8XSxe09ER', BMF_COORD_TYPE.BD09LL); } else if(Platform.isAndroid) { - BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); + BMFMapSDK.setCoordType(BMF_COORD_TYPE.COMMON); } } diff --git a/lib/main_page.dart b/lib/main_page.dart index 096369a2..9c783691 100644 --- a/lib/main_page.dart +++ b/lib/main_page.dart @@ -123,12 +123,7 @@ class _MainPage extends State { BaseData baseDate = await ApiService(Dio(), context: context, token: sharedPreferences.getString('token')) .queryInfo(); - - SharedPreferences.getInstance().then( - (value) => { - value.setString('user', jsonEncode(baseDate.data)), - }, - ); + sharedPreferences.setString('user', jsonEncode(baseDate.data)); } requestPermission() async { diff --git a/lib/order/store_selector_page.dart b/lib/order/store_selector_page.dart index 1b706de7..3dd8027f 100644 --- a/lib/order/store_selector_page.dart +++ b/lib/order/store_selector_page.dart @@ -5,6 +5,7 @@ import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; +import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; @@ -60,13 +61,16 @@ class _StoreSelectorPage extends State { } else { latLng = BMFCoordinate(event["latitude"], event["longitude"]); } - if (Navigator.of(context).canPop()) { - Navigator.of(context).pop(); - } - saveLatLng( - latLng, event["province"], event["city"], event["district"]); - queryStore("${event["latitude"]}", "${event["longitude"]}", - event["province"], event["city"], event["district"]); + BMFCalculateUtils.coordConvert( + coordinate: latLng, + fromType: BMF_COORD_TYPE.COMMON, + toType: BMF_COORD_TYPE.BD09LL).then((value) { + this.latLng = value; + saveLatLng( + value, event["province"], event["city"], event["district"]); + queryStore("${value.latitude}", "${value.longitude}", + event["province"], event["city"], event["district"]); + }); } }); } diff --git a/lib/union/union_page.dart b/lib/union/union_page.dart index 586b1c7c..f600d5aa 100644 --- a/lib/union/union_page.dart +++ b/lib/union/union_page.dart @@ -1,15 +1,15 @@ import 'dart:io'; import 'dart:ui'; -import 'package:amap_flutter_location/amap_flutter_location.dart'; -import 'package:amap_flutter_location/amap_location_option.dart'; import 'package:android_intent_plus/android_intent.dart'; import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; +import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; +import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/main.dart'; @@ -21,8 +21,6 @@ import 'package:huixiang/view_widget/classic_header.dart'; import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/icon_text.dart'; import 'package:huixiang/view_widget/item_title.dart'; -import 'package:amap_flutter_base/amap_flutter_base.dart'; -import 'package:amap_flutter_map/amap_flutter_map.dart'; import 'package:huixiang/view_widget/request_permission.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; @@ -30,6 +28,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'dart:typed_data'; import 'package:flutter/rendering.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; class UnionPage extends StatefulWidget { @override @@ -40,28 +39,15 @@ class UnionPage extends StatefulWidget { class _UnionPage extends State with AutomaticKeepAliveClientMixin, WidgetsBindingObserver { - //默认设置为不使用自定义地图,如果需要直接显示,在初始化是设置为true - CustomStyleOptions _customStyleOptions = CustomStyleOptions(false); //加载自定义地图样式 void _loadCustomData() async { - if (null == _customStyleOptions) { - _customStyleOptions = CustomStyleOptions(false); - } - ByteData styleByteData = - await rootBundle.load('assets/map_style/style.data'); - _customStyleOptions.styleData = styleByteData.buffer.asUint8List(); - ByteData styleExtraByteData = - await rootBundle.load('assets/map_style/style_extra.data'); - _customStyleOptions.styleExtraData = - styleExtraByteData.buffer.asUint8List(); - //如果需要加载完成后直接展示自定义地图,可以通过setState修改CustomStyleOptions的enable为true setState(() { - _customStyleOptions.enabled = true; + _mapController.setCustomMapStyle('assets/map_style/chatian.sty', 0); }); } - AMapFlutterLocation aMapFlutterLocation; + LocationFlutterPlugin aMapFlutterLocation; RefreshController refreshController = RefreshController(initialRefresh: false); @@ -70,7 +56,6 @@ class _UnionPage extends State super.dispose(); WidgetsBinding.instance.removeObserver(this); aMapFlutterLocation.stopLocation(); - aMapFlutterLocation.destroy(); refreshController.dispose(); } @@ -105,36 +90,38 @@ class _UnionPage extends State WidgetsBinding.instance.addObserver(this); if (aMapFlutterLocation == null) { - AMapFlutterLocation.setApiKey("f39d1daa020a56f208eb2519f63e9534", - "feaae7986201b571cace1b83728be5bb"); - aMapFlutterLocation = AMapFlutterLocation(); - aMapFlutterLocation.onLocationChanged().listen((event) { + aMapFlutterLocation = LocationFlutterPlugin(); + aMapFlutterLocation.onResultCallback().listen((event) { if (event != null && event["latitude"] != null && event["longitude"] != null) { print("location: $event"); if (event["latitude"] is String && event["longitude"] is String) { - latLng = LatLng(double.tryParse(event["latitude"]), + latLng = BMFCoordinate(double.tryParse(event["latitude"]), double.tryParse(event["longitude"])); } else { - latLng = LatLng(event["latitude"], event["longitude"]); + latLng = BMFCoordinate(event["latitude"], event["longitude"]); } - saveLatLng( - latLng, event["province"], event["city"], event["district"]); - queryStore( - "${event["latitude"]}", - "${event["longitude"]}", - event["province"], - event["city"], - event["district"], - editingController.text); - if (_mapController != null) - _mapController.moveCamera( - CameraUpdate.newCameraPosition(CameraPosition( - target: latLng, - zoom: 15.0, - )), - ); + BMFCalculateUtils.coordConvert( + coordinate: latLng, + fromType: BMF_COORD_TYPE.COMMON, + toType: BMF_COORD_TYPE.BD09LL).then((value) { + this.latLng = value; + saveLatLng( + value, event["province"], event["city"], event["district"]); + queryStore( + "${value.latitude}", + "${value.longitude}", + event["province"], + event["city"], + event["district"], + editingController.text); + if (_mapController != null) + _mapController.updateMapOptions(BMFMapOptions( + center: value, + zoomLevel: 15, + )); + }); } }); @@ -146,15 +133,25 @@ class _UnionPage extends State }); } - aMapFlutterLocation.setLocationOption(AMapLocationOption( - needAddress: true, - onceLocation: true, - locationMode: AMapLocationMode.Hight_Accuracy, - desiredAccuracy: DesiredAccuracy.HundredMeters, - desiredLocationAccuracyAuthorizationMode: - AMapLocationAccuracyAuthorizationMode.FullAndReduceAccuracy, - pausesLocationUpdatesAutomatically: true, - )); + aMapFlutterLocation.prepareLoc({ + "coorType": "bd09ll", + "isNeedAddres": false, + "isNeedAltitude": false, + "isNeedLocationPoiList": false, + "isNeedLocationDescribe": false, + "isNeedNewVersionRgc": false, + "scanspan": 0, + "openGps": true, + "locationMode": 2, + }, { + "locationMode": "kCLLocationAccuracyBest", + "locationTimeout": 10, + "reGeocodeTimeout": 10, + "activityType": "CLActivityTypeAutomotiveNavigation", + "BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL", + "BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL", + "isNeedNewVersionRgc": false, + }); _loadCustomData(); @@ -162,9 +159,9 @@ class _UnionPage extends State startLocation(); } - LatLng latLng; + BMFCoordinate latLng; - saveLatLng(LatLng latLng, province, city, district) async { + saveLatLng(BMFCoordinate latLng, province, city, district) async { SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.setString("latitude", "${latLng.latitude}"); await prefs.setString("longitude", "${latLng.longitude}"); @@ -186,7 +183,7 @@ class _UnionPage extends State value.containsKey("city") && value.containsKey("district")) { - latLng = LatLng(double.tryParse(value.getString("latitude")), + latLng = BMFCoordinate(double.tryParse(value.getString("latitude")), double.tryParse(value.getString("longitude"))), queryStore( value.getString("latitude"), @@ -198,14 +195,10 @@ class _UnionPage extends State ), setState(() { if (_mapController != null) { - _mapController.moveCamera( - CameraUpdate.newCameraPosition( - CameraPosition( - target: latLng, - zoom: 15.0, - ), - ), - ); + _mapController.updateMapOptions(BMFMapOptions( + center: latLng, + zoomLevel: 15, + )); } }) } @@ -235,7 +228,7 @@ class _UnionPage extends State storeList = (baseData.data as List) .map((e) => Store.fromJson(e)) .toList(); - buildMarker(); + // buildMarker(); refreshController.refreshCompleted(); if (mounted) setState(() {}); } else { @@ -243,34 +236,20 @@ class _UnionPage extends State } } - RepaintBoundary repaintBoundary; - - buildMarker() async { - markers.clear(); - - BitmapDescriptor bitmapDescriptor = await BitmapDescriptor.fromAssetImage( - ImageConfiguration( - bundle: DefaultAssetBundle.of(context), - devicePixelRatio: MediaQuery.of(context)?.devicePixelRatio ?? 1.0, - locale: Localizations.localeOf(context), - textDirection: Directionality.of(context), - size: Size(35.w, 35.h), - platform: defaultTargetPlatform, - ), - "assets/image/icon_map_marker.png"); - - markers.addAll(storeList.map((element) => Marker( - position: LatLng(double.tryParse(element.latitude), - double.tryParse(element.longitude)), - anchor: Offset(0.5, 0.9), - clickable: false, - icon: bitmapDescriptor, - infoWindowEnable: true, - ))); - if (mounted) setState(() {}); - } - - List markers = []; + // buildMarker() async { + // markers.clear(); + // markers.addAll(storeList.map((element) => BMFMarker( + // position: BMFCoordinate(double.tryParse(element.latitude), + // double.tryParse(element.longitude)), + // centerOffset: BMFPoint(0.5, 0.9), + // enabled: false, + // icon: "assets/image/icon_map_marker.png", + // draggable: false, + // ))); + // if (mounted) setState(() {}); + // } + // + // List markers = []; @override Widget build(BuildContext context) { @@ -306,24 +285,17 @@ class _UnionPage extends State // headerSliverBuilder: (context, inner) { // return [ // SliverOverlapAbsorber( - // sliver: buildSliverAppBar(AMapWidget( - // initialCameraPosition: CameraPosition( - // target: LatLng(30.553111, 114.342366), - // zoom: 12.0, + // sliver: buildSliverAppBar(BMFMapWidget( + // mapOptions: BMFMapOptions( + // center: BMFCoordinate(30.553111, 114.342366), + // zoomLevel: 12, // ), - // onMapCreated: onMapCreated, - // apiKey: aMapApiKeys, - // touchPoiEnabled: true, - // markers: markers.toSet(), - // scrollGesturesEnabled: true, - // customStyleOptions: _customStyleOptions, - // onPoiTouched: (poiTouch) { - // FocusScope.of(context).requestFocus(FocusNode()); - // }, - // gestureRecognizers: >[ - // Factory( - // () => EagerGestureRecognizer()), - // ].toSet(), + // onBMFMapCreated: onMapCreated, + // // customStyleOptions: _customStyleOptions, + // // gestureRecognizers: >[ + // // Factory( + // // () => EagerGestureRecognizer()), + // // ].toSet(), // )), // handle: // NestedScrollView.sliverOverlapAbsorberHandleFor(context), @@ -368,7 +340,7 @@ class _UnionPage extends State itemCount: storeList == null ? 0 : storeList.length, // padding: EdgeInsets.only(top: 8.h, bottom: 84.h + (375.h - 88.h) + 4.h), padding: EdgeInsets.only( - top: 17.h, bottom: 84.h /* + (375.h - 88.h) + 4.h*/), + top: 8.h, bottom: 84.h /* + (375.h - 88.h) + 4.h*/), physics: NeverScrollableScrollPhysics(), itemBuilder: (context, position) { return GestureDetector( @@ -460,10 +432,10 @@ class _UnionPage extends State }); } - AMapController _mapController; + BMFMapController _mapController; TextEditingController editingController = TextEditingController(); - void onMapCreated(AMapController controller) { + void onMapCreated(BMFMapController controller) { _mapController = controller; } @@ -473,16 +445,17 @@ class _UnionPage extends State margin: EdgeInsets.fromLTRB(16.w, 40, 16.w, 0), padding: EdgeInsets.fromLTRB(0, 6.h, 0, 6.h), decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(4)), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(12), - offset: Offset(0, 3), - blurRadius: 14, - spreadRadius: 0, - ) - ]), + color: Colors.white, + borderRadius: BorderRadius.all(Radius.circular(4)), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(12), + offset: Offset(0, 3), + blurRadius: 14, + spreadRadius: 0, + ) + ], + ), child: TextField( textInputAction: TextInputAction.search, onEditingComplete: () { @@ -513,81 +486,81 @@ class _UnionPage extends State ); } - Widget buildSliverAppBar(AMapWidget map) { - return SliverAppBar( - // 滑上去时搜索隐藏 - // floating: true, - // snap: true, - pinned: true, - backgroundColor: Color(0xFFFAFAFA), - elevation: 0, - automaticallyImplyLeading: false, - title: Container( - height: 36.h, - margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0), - padding: EdgeInsets.fromLTRB(0, 6.h, 0, 6.h), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(4)), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(12), - offset: Offset(0, 3), - blurRadius: 14, - spreadRadius: 0, - ) - ]), - child: TextField( - textInputAction: TextInputAction.search, - onEditingComplete: () { - startLocation(); - }, - controller: editingController, - cursorHeight: 30.h, - decoration: InputDecoration( - contentPadding: EdgeInsets.symmetric(vertical: 12.h), - prefixIcon: Icon( - Icons.search, - size: 24, - color: Colors.black, - ), - suffixIcon: InkWell( - onTap: () { - editingController.clear(); - }, - child: Icon( - Icons.close, - size: 19, - color: Colors.grey, - ), - ), - border: InputBorder.none, - ), - ), - ), - flexibleSpace: FlexibleSpaceBar( - background: Container( - child: map, - ), - ), - expandedHeight: 375.h, - bottom: PreferredSize( - preferredSize: Size(double.infinity, 52.h), - child: Container( - padding: EdgeInsets.only(top: 6.h), - color: Color(0xFFFAFAFA), - child: ItemTitle( - text: S.of(context).jingbilianmenghuiyuandian, - imgPath: "assets/image/icon_union_store.png", - ), - ), - ), - ); - } + // Widget buildSliverAppBar(BMFMapWidget map) { + // return SliverAppBar( + // // 滑上去时搜索隐藏 + // // floating: true, + // // snap: true, + // pinned: true, + // backgroundColor: Color(0xFFFAFAFA), + // elevation: 0, + // automaticallyImplyLeading: false, + // title: Container( + // height: 36.h, + // margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0), + // padding: EdgeInsets.fromLTRB(0, 6.h, 0, 6.h), + // decoration: BoxDecoration( + // color: Colors.white, + // borderRadius: BorderRadius.all(Radius.circular(4)), + // boxShadow: [ + // BoxShadow( + // color: Colors.black.withAlpha(12), + // offset: Offset(0, 3), + // blurRadius: 14, + // spreadRadius: 0, + // ) + // ]), + // child: TextField( + // textInputAction: TextInputAction.search, + // onEditingComplete: () { + // startLocation(); + // }, + // controller: editingController, + // cursorHeight: 30.h, + // decoration: InputDecoration( + // contentPadding: EdgeInsets.symmetric(vertical: 12.h), + // prefixIcon: Icon( + // Icons.search, + // size: 24, + // color: Colors.black, + // ), + // suffixIcon: InkWell( + // onTap: () { + // editingController.clear(); + // }, + // child: Icon( + // Icons.close, + // size: 19, + // color: Colors.grey, + // ), + // ), + // border: InputBorder.none, + // ), + // ), + // ), + // flexibleSpace: FlexibleSpaceBar( + // background: Container( + // child: map, + // ), + // ), + // expandedHeight: 375.h, + // bottom: PreferredSize( + // preferredSize: Size(double.infinity, 52.h), + // child: Container( + // padding: EdgeInsets.only(top: 6.h), + // color: Color(0xFFFAFAFA), + // child: ItemTitle( + // text: S.of(context).jingbilianmenghuiyuandian, + // imgPath: "assets/image/icon_union_store.png", + // ), + // ), + // ), + // ); + // } Widget buildStoreItem(Store store, position) { return Container( - margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 16.h), + margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 8.h), padding: EdgeInsets.fromLTRB(20.w, 20.h, 20.w, 20.h), decoration: BoxDecoration( color: Colors.white, @@ -651,6 +624,9 @@ class _UnionPage extends State ), ], ), + SizedBox( + height: 4.h, + ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, diff --git a/pubspec.lock b/pubspec.lock index 6dc89927..4ce17977 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -35,7 +35,7 @@ packages: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.6.1" + version: "2.5.0" barcode: dependency: transitive description: @@ -307,6 +307,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.1" + flutter_bmflocation: + dependency: "direct main" + description: + name: flutter_bmflocation + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.4" flutter_cache_manager: dependency: transitive description: @@ -886,7 +893,7 @@ packages: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.3.0" + version: "0.2.19" timing: dependency: transitive description: @@ -1049,7 +1056,7 @@ packages: name: win32 url: "https://pub.flutter-io.cn" source: hosted - version: "2.2.5" + version: "2.0.5" xdg_directories: dependency: transitive description: @@ -1072,5 +1079,5 @@ packages: source: hosted version: "3.1.0" sdks: - dart: ">=2.13.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 68b17f91..c9555a4c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -45,7 +45,7 @@ dependencies: permission_handler: ^5.0.1+1 -# flutter_bmflocation: ^1.0.4 + flutter_bmflocation: ^1.0.3 flutter_baidu_mapapi_base: ^2.0.1 flutter_baidu_mapapi_map: ^2.0.1 flutter_baidu_mapapi_search: ^2.0.1