From b4908ceb4c6e646014e07ace4666cc42bcafa236 Mon Sep 17 00:00:00 2001
From: zhuce <821293938@qq.com>
Date: Sat, 16 Mar 2024 15:52:12 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E6=9D=83=E9=99=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ios/Podfile | 68 ++++++++++++++-
ios/Podfile.lock | 8 +-
ios/Runner/Info.plist | 8 ++
lib/const_config.dart | 7 +-
lib/pages/home/home_page.dart | 58 -------------
lib/pages/home/widgets/map_widget.dart | 115 +++++++++++++++++++++++++
lib/pages/login/login_page.dart | 3 +
pubspec.lock | 48 +++++++++++
pubspec.yaml | 1 +
9 files changed, 254 insertions(+), 62 deletions(-)
diff --git a/ios/Podfile b/ios/Podfile
index d97f17e..0daa28d 100644
--- a/ios/Podfile
+++ b/ios/Podfile
@@ -37,8 +37,74 @@ target 'Runner' do
end
end
+
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
+
+ # Start of the permission_handler configuration
+ target.build_configurations.each do |config|
+
+ # You can enable the permissions needed here. For example to enable camera
+ # permission, just remove the `#` character in front so it looks like this:
+ #
+ # ## dart: PermissionGroup.camera
+ # 'PERMISSION_CAMERA=1'
+ #
+ # Preprocessor definitions can be found at: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler_apple/ios/Classes/PermissionHandlerEnums.h
+ config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
+ '$(inherited)',
+
+ ## dart: [PermissionGroup.calendarWriteOnly, PermissionGroup.calendar (iOS 16 and below)]
+ # 'PERMISSION_EVENTS=1',
+
+ ## dart: [PermissionGroup.calendarFullAccess, PermissionGroup.calendar (iOS 17 and above)]
+ # 'PERMISSION_EVENTS_FULL_ACCESS=1',
+
+ ## dart: PermissionGroup.reminders
+ # 'PERMISSION_REMINDERS=1',
+
+ ## dart: PermissionGroup.contacts
+ # 'PERMISSION_CONTACTS=1',
+
+ ## dart: PermissionGroup.camera
+ 'PERMISSION_CAMERA=1',
+
+ ## dart: PermissionGroup.microphone
+ # 'PERMISSION_MICROPHONE=1',
+
+ ## dart: PermissionGroup.speech
+ # 'PERMISSION_SPEECH_RECOGNIZER=1',
+
+ ## dart: PermissionGroup.photos
+ 'PERMISSION_PHOTOS=1',
+
+ ## dart: PermissionGroup.photosAddOnly
+ # 'PERMISSION_PHOTOS_ADD_ONLY=1',
+
+ ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
+ 'PERMISSION_LOCATION=1',
+
+ ## dart: PermissionGroup.notification
+ 'PERMISSION_NOTIFICATIONS=1',
+
+ ## dart: PermissionGroup.mediaLibrary
+ # 'PERMISSION_MEDIA_LIBRARY=1',
+
+ ## dart: PermissionGroup.sensors
+ # 'PERMISSION_SENSORS=1',
+
+ ## dart: PermissionGroup.bluetooth
+ # 'PERMISSION_BLUETOOTH=1',
+
+ ## dart: PermissionGroup.appTrackingTransparency
+ # 'PERMISSION_APP_TRACKING_TRANSPARENCY=1',
+
+ ## dart: PermissionGroup.criticalAlerts
+ # 'PERMISSION_CRITICAL_ALERTS=1'
+ ]
+
+ end
+ # End of the permission_handler configuration
end
-end
+end
\ No newline at end of file
diff --git a/ios/Podfile.lock b/ios/Podfile.lock
index 10268b3..955bfc9 100644
--- a/ios/Podfile.lock
+++ b/ios/Podfile.lock
@@ -20,6 +20,8 @@ PODS:
- ZXSDK
- GTSDK (3.0.5.0):
- GTCommonSDK (> 3.0.9.0)
+ - permission_handler_apple (9.3.0):
+ - Flutter
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
@@ -31,6 +33,7 @@ DEPENDENCIES:
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- Flutter (from `Flutter`)
- getuiflut (from `.symlinks/plugins/getuiflut/ios`)
+ - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
SPEC REPOS:
@@ -53,6 +56,8 @@ EXTERNAL SOURCES:
:path: Flutter
getuiflut:
:path: ".symlinks/plugins/getuiflut/ios"
+ permission_handler_apple:
+ :path: ".symlinks/plugins/permission_handler_apple/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
@@ -67,9 +72,10 @@ SPEC CHECKSUMS:
getuiflut: 8628ba2b64a738a847a07d2b67e0ac305778e2ee
GTCommonSDK: 2be8c2d5b094929f81b64dba8767bf110bae78de
GTSDK: cc04d169c5c6cb8f8884849153eaac9e6ccfdd7c
+ permission_handler_apple: 036b856153a2b1f61f21030ff725f3e6fece2b78
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695
ZXSDK: 414bed508b670437a9bdf7c75d49816b8cb7b2d4
-PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796
+PODFILE CHECKSUM: b2ff02a7210c740947b0635c5db14e8d36382e1f
COCOAPODS: 1.15.2
diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist
index 32bcbab..d3f3705 100644
--- a/ios/Runner/Info.plist
+++ b/ios/Runner/Info.plist
@@ -45,5 +45,13 @@
UIApplicationSupportsIndirectInputEvents
+ NSLocationAlwaysAndWhenInUseUsageDescription
+ 需要使用您的定位,地图附近显示停车、车辆信息
+ NSLocationAlwaysUsageDescription
+ 需要使用您的定位,地图附近显示停车、车辆信息
+ NSLocationUsageDescription
+ 需要使用您的定位,地图附近显示停车、车辆信息
+ NSLocationWhenInUseUsageDescription
+ 需要使用您的定位,地图附近显示停车、车辆信息
diff --git a/lib/const_config.dart b/lib/const_config.dart
index 3eaf32a..2e26629 100644
--- a/lib/const_config.dart
+++ b/lib/const_config.dart
@@ -2,13 +2,16 @@ import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:amap_flutter_map/amap_flutter_map.dart';
class ConstConfig {
+
+ static const String androidKey='c715f41c63e5bd7faef2b53de7438709';
+ static const String iosKey='8c545f5186ddd9d2c585693f72b4790a';
///配置您申请的apikey,在此处配置之后,可以在初始化[AMapWidget]时,通过`apiKey`属性设置
///
///注意:使用[AMapWidget]的`apiKey`属性设置的key的优先级高于通过Native配置key的优先级,
///使用[AMapWidget]的`apiKey`属性配置后Native配置的key将失效,请根据实际情况选择使用
static const AMapApiKey amapApiKeys = AMapApiKey(
- androidKey: 'c715f41c63e5bd7faef2b53de7438709',
- iosKey: '8c545f5186ddd9d2c585693f72b4790a');
+ androidKey: androidKey,
+ iosKey: iosKey);
///高德隐私合规声明,这里只是示例,实际使用中请按照实际参数设置[AMapPrivacyStatement]的'hasContains''hasShow''hasAgree'这三个参数
///
diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart
index 620d289..aeb14cb 100644
--- a/lib/pages/home/home_page.dart
+++ b/lib/pages/home/home_page.dart
@@ -1,6 +1,4 @@
-import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:autosos_flutter/config/theme_colors.dart';
-import 'package:autosos_flutter/const_config.dart';
import 'package:autosos_flutter/pages/home/widgets/image_block.dart';
import 'package:autosos_flutter/pages/home/widgets/map_widget.dart';
import 'package:autosos_flutter/pages/home/widgets/number_block.dart';
@@ -15,7 +13,6 @@ class HomePage extends StatefulWidget {
class _HomePageState extends State {
bool enabled = false;
- late AMapController _mapController;
@override
Widget build(BuildContext context) {
@@ -227,59 +224,4 @@ class _HomePageState extends State {
),
);
}
-
- Widget buildBottomWidget() {
- AMapWidget map = AMapWidget(
- ///必须正确设置的合规隐私声明,否则SDK不会工作,会造成地图白屏等问题。
- privacyStatement: ConstConfig.amapPrivacyStatement,
- apiKey: ConstConfig.amapApiKeys,
- mapType: MapType.navi,
- scaleEnabled: false,
- myLocationStyleOptions: MyLocationStyleOptions(
- true,
- circleFillColor: Colors.lightBlue,
- circleStrokeColor: Colors.blue,
- circleStrokeWidth: 1,
- ),
- onMapCreated: (AMapController controller) {
- setState(() {
- _mapController = controller;
- getApprovalNumber();
- });
- },
- );
- return Expanded(
- child: Stack(
- children: [
- Container(
- margin: const EdgeInsets.only(top: 10, bottom: 10),
- decoration: const BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(5))),
- child: map,
- ),
- Positioned(
- bottom: 20,
- right: 20,
- child: Image.asset(
- "images/3.0x/current_location.png",
- width: 30,
- height: 30,
- ),
- )
- ],
- ));
- }
-
- ///获取审图号
- void getApprovalNumber() async {
- //普通地图审图号
- String? mapContentApprovalNumber =
- await _mapController.getMapContentApprovalNumber();
- //卫星地图审图号
- String? satelliteImageApprovalNumber =
- await _mapController.getSatelliteImageApprovalNumber();
- print('地图审图号(普通地图): $mapContentApprovalNumber');
- print('地图审图号(卫星地图): $satelliteImageApprovalNumber');
- }
}
diff --git a/lib/pages/home/widgets/map_widget.dart b/lib/pages/home/widgets/map_widget.dart
index 24cdf88..399bbe5 100644
--- a/lib/pages/home/widgets/map_widget.dart
+++ b/lib/pages/home/widgets/map_widget.dart
@@ -1,6 +1,12 @@
+import 'dart:async';
+import 'dart:io';
+
+import 'package:amap_flutter_location/amap_flutter_location.dart';
+import 'package:amap_flutter_location/amap_location_option.dart';
import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:autosos_flutter/const_config.dart';
import 'package:flutter/material.dart';
+import 'package:permission_handler/permission_handler.dart';
@@ -13,6 +19,69 @@ class MapWidget extends StatefulWidget {
class _MapWidgetState extends State {
late AMapController _mapController;
+ late Map _locationResult;
+
+ @override
+ void initState() {
+ super.initState();
+ /// 设置是否已经包含高德隐私政策并弹窗展示显示用户查看,如果未包含或者没有弹窗展示,高德定位SDK将不会工作
+ ///
+ /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
+ /// 必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意
+ ///
+ /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
+ ///
+ /// [hasContains] 隐私声明中是否包含高德隐私政策说明
+ ///
+ /// [hasShow] 隐私权政策是否弹窗展示告知用户
+ AMapFlutterLocation.updatePrivacyShow(true, true);
+
+ /// 设置是否已经取得用户同意,如果未取得用户同意,高德定位SDK将不会工作
+ ///
+ /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
+ ///
+ /// 必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意
+ ///
+ /// [hasAgree] 隐私权政策是否已经取得用户同意
+ AMapFlutterLocation.updatePrivacyAgree(true);
+
+ /// 动态申请定位权限
+ requestPermission();
+
+ ///设置Android和iOS的apiKey
+ ///
+ /// 定位Flutter插件提供了单独的设置ApiKey的接口,
+ /// 使用接口的优先级高于通过Native配置ApiKey的优先级(通过Api接口配置后,通过Native配置文件设置的key将不生效),
+ /// 使用时可根据实际情况决定使用哪种方式
+ ///
+ ///key的申请请参考高德开放平台官网说明
+ ///
+ ///Android: https://lbs.amap.com/api/android-location-sdk/guide/create-project/get-key
+ ///
+ ///iOS: https://lbs.amap.com/api/ios-location-sdk/guide/create-project/get-key
+ AMapFlutterLocation.setApiKey(
+ ConstConfig.androidKey, ConstConfig.iosKey);
+
+
+ ///iOS 获取native精度类型
+ if (Platform.isIOS) {
+ requestAccuracyAuthorization();
+ }
+
+ ///注册定位结果监听
+ _locationListener = _locationPlugin
+ .onLocationChanged()
+ .listen((Map result) {
+ setState(() {
+ _locationResult = result;
+ });
+ print("locationRest=$_locationResult");
+ });
+ }
+
+ late StreamSubscription