Compare commits

...

3 Commits

Author SHA1 Message Date
zhuce ee11c80e9f 在地图上显示定位 2024-03-16 18:11:34 +08:00
zhuce b4908ceb4c 定位权限 2024-03-16 15:52:12 +08:00
zhuce 97128918e4 map_widget 2024-03-16 14:15:04 +08:00
9 changed files with 345 additions and 66 deletions

View File

@ -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

View File

@ -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

View File

@ -45,5 +45,13 @@
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>需要使用您的定位,地图附近显示停车、车辆信息</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>需要使用您的定位,地图附近显示停车、车辆信息</string>
<key>NSLocationUsageDescription</key>
<string>需要使用您的定位,地图附近显示停车、车辆信息</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>需要使用您的定位,地图附近显示停车、车辆信息</string>
</dict>
</plist>

View File

@ -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`keyNativekey
///使[AMapWidget]`apiKey`Nativekey使
static const AMapApiKey amapApiKeys = AMapApiKey(
androidKey: 'c715f41c63e5bd7faef2b53de7438709',
iosKey: '8c545f5186ddd9d2c585693f72b4790a');
androidKey: androidKey,
iosKey: iosKey);
///使[AMapPrivacyStatement]'hasContains''hasShow''hasAgree'
///

View File

@ -1,11 +1,9 @@
import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:autosos_flutter/const_config.dart';
import 'package:autosos_flutter/config/theme_colors.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';
import 'package:flutter/material.dart';
import '../../config/theme_colors.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@ -15,7 +13,6 @@ class HomePage extends StatefulWidget {
class _HomePageState extends State<HomePage> {
bool enabled = false;
late AMapController _mapController;
@override
Widget build(BuildContext context) {
@ -37,14 +34,14 @@ class _HomePageState extends State<HomePage> {
)),
backgroundColor: const Color(0xFFF3F3F3),
body: PopScope(
canPop: false,
canPop: true, //
child: Padding(
padding: const EdgeInsets.all(10),
child: Column(
children: [
buildTopWidget(),
buildMiddleWidget(),
buildBottomWidget()
const MapWidget()
],
),
),
@ -227,59 +224,4 @@ class _HomePageState extends State<HomePage> {
),
);
}
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');
}
}

View File

@ -0,0 +1,202 @@
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';
import 'package:amap_flutter_base/amap_flutter_base.dart';
class MapWidget extends StatefulWidget {
const MapWidget({super.key});
@override
State<MapWidget> createState() => _MapWidgetState();
}
class _MapWidgetState extends State<MapWidget> {
late AMapController _mapController;
Map<String, Object> _locationResult = {};
late StreamSubscription<Map<String, Object>> _locationListener;
final AMapFlutterLocation _locationPlugin = AMapFlutterLocation();
@override
void dispose() {
super.dispose();
_locationListener.cancel();
_locationPlugin.destroy();
}
@override
void initState() {
super.initState();
/// SDK
///
/// SDK使https://lbs.amap.com/news/sdkhgsy
/// <b> App</b>
///
/// SDK使https://lbs.amap.com/news/sdkhgsy
///
/// [hasContains]
///
/// [hasShow]
AMapFlutterLocation.updatePrivacyShow(true, true);
/// SDK
///
/// SDK使https://lbs.amap.com/news/sdkhgsy
///
/// <b>, App</b>
///
/// [hasAgree]
AMapFlutterLocation.updatePrivacyAgree(true);
///
requestPermission();
///AndroidiOSapiKey<br>
///
/// FlutterApiKey
/// 使NativeApiKeyApiNativekey
/// 使使
///
///key<br>
///
///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();
}
_locationPlugin.setLocationOption(AMapLocationOption());
///
_locationListener = _locationPlugin
.onLocationChanged()
.listen((Map<String, Object> result) {
setState(() {
_locationResult = result;
});
print("location=$_locationResult");
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
_moveCamera(_locationResult);
});
});
_locationPlugin.startLocation();
}
@override
Widget build(BuildContext context) {
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 _moveCamera(Map<String,Object> result) {
double lat = double.parse(result['latitude'] as String);
double lng = double.parse(result['longitude'] as String);
_mapController.moveCamera(
CameraUpdate.newCameraPosition(CameraPosition(target: LatLng(lat,lng))));
}
///
void getApprovalNumber() async {
//
String? mapContentApprovalNumber =
await _mapController.getMapContentApprovalNumber();
//
String? satelliteImageApprovalNumber =
await _mapController.getSatelliteImageApprovalNumber();
print('地图审图号(普通地图): $mapContentApprovalNumber');
print('地图审图号(卫星地图): $satelliteImageApprovalNumber');
}
void requestPermission() async {
//
bool hasLocationPermission = await requestLocationPermission();
if (hasLocationPermission) {
print("定位权限申请通过");
} else {
print("定位权限申请不通过");
}
}
///
/// true false
Future<bool> requestLocationPermission() async {
//
var status = await Permission.locationAlways.status;
if (status == PermissionStatus.granted) {
//
return true;
} else {
//
status = await Permission.locationAlways.request();
if (status == PermissionStatus.granted) {
return true;
} else {
return false;
}
}
}
///iOS nativeaccuracyAuthorization
void requestAccuracyAuthorization() async {
AMapAccuracyAuthorization currentAccuracyAuthorization =
await _locationPlugin.getSystemAccuracyAuthorization();
if (currentAccuracyAuthorization ==
AMapAccuracyAuthorization.AMapAccuracyAuthorizationFullAccuracy) {
print("精确定位类型");
} else if (currentAccuracyAuthorization ==
AMapAccuracyAuthorization.AMapAccuracyAuthorizationReducedAccuracy) {
print("模糊定位类型");
} else {
print("未知定位类型");
}
}
}

View File

@ -19,6 +19,8 @@ class _LoginPageState extends State<LoginPage> {
SPUtil spUtil = SPUtil();
@override
Widget build(BuildContext context) {
_unameController.text = "14725803690";
_pwdController.text = "123456";
return Scaffold(
appBar: AppBar(),
body: Column(
@ -70,6 +72,7 @@ class _LoginPageState extends State<LoginPage> {
children: [
Expanded(
child: TextField(
obscureText: true,
controller: _pwdController,
decoration: const InputDecoration(hintText: "请输入密码"),
))

View File

@ -312,6 +312,54 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.1"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
sha256: "74e962b7fad7ff75959161bb2c0ad8fe7f2568ee82621c9c2660b751146bfe44"
url: "https://pub.flutter-io.cn"
source: hosted
version: "11.3.0"
permission_handler_android:
dependency: transitive
description:
name: permission_handler_android
sha256: "1acac6bae58144b442f11e66621c062aead9c99841093c38f5bcdcc24c1c3474"
url: "https://pub.flutter-io.cn"
source: hosted
version: "12.0.5"
permission_handler_apple:
dependency: transitive
description:
name: permission_handler_apple
sha256: bdafc6db74253abb63907f4e357302e6bb786ab41465e8635f362ee71fd8707b
url: "https://pub.flutter-io.cn"
source: hosted
version: "9.4.0"
permission_handler_html:
dependency: transitive
description:
name: permission_handler_html
sha256: "54bf176b90f6eddd4ece307e2c06cf977fb3973719c35a93b85cc7093eb6070d"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.1"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
sha256: "23dfba8447c076ab5be3dee9ceb66aad345c4a648f0cac292c77b1eb0e800b78"
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.2.0"
permission_handler_windows:
dependency: transitive
description:
name: permission_handler_windows
sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.1"
platform:
dependency: transitive
description:

View File

@ -40,6 +40,7 @@ dependencies:
uuid: ^4.3.3
device_info_plus: ^9.1.2
getuiflut: ^0.2.25
permission_handler: ^11.3.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.