如何获取Sha1:
开发板:
找到自己电脑jdk的位置进入其中bin文件夹路径下,输入命令-list -v -keystore debug.keystore
C: ->回车
cd Users\Administrator ->回车
cd .android ->回车
C:\Users\ Administrator \.android>
"C:\Program Files\Java\jdk1.8.0_231\bin\keytool" -list -v -keystore debug.keystore
发布版:
E:\WenZheProject2021\ZhengJianLaoWu\rcb-android\zjlw.jks
为数字签名的路径"C:\Program Files\Java\jdk1.8.0_231\bin\keytool" -list -v -keystore E:\WenZheProject2021\ZhengJianLaoWu\rcb-android\zjlw.jks
(1)打开cmd
(2)cd C:\Program Files\Java\jdk1.8.0_231\bin 回车
(3)将该项目打包用的jks文件粘贴到C:\Program Files\Java\jdk1.8.0_231\bin文件夹下
(4)keytool -list -v -keystore zjlw.jks 回车
(5)输入密码
注意:如果路径中文件夹命名带有空格的话需要将路径用""包裹起来、例如"C:\Program Files\Java\jdk1.8.0_231\bin\keytool"
pubspec.yaml
中添加:
amap_flutter_map: ^3.0.0
执行命令:flutter pub get
①、由于高德地图Flutter插件内不包含基础SDK包,所以需要单独引入地图基础SDK,在android文件加下的build.gradle文件中添加如下代码:
dependencies {
//高德地图Flutter插件内不包含基础SDK包,使用时请参考官网关于集成Android地图SDK和iOS地图SDK说明配置地图SDK
implementation('com.amap.api:3dmap:9.4.0')
}
implementation('com.amap.api:map2d:6.0.0')
E/AndroidRuntime(11569): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/amap/api/maps/AMapOptions;
E/AndroidRuntime(11569): at com.amap.flutter.map.AMapOptionsBuilder.<init>(AMapOptionsBuilder.java:27)
E/AndroidRuntime(11569): at com.amap.flutter.map.AMapPlatformViewFactory.create(AMapPlatformViewFactory.java:35)
E/AndroidRuntime(11569): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:197)
E/AndroidRuntime(11569): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122)
E/AndroidRuntime(11569): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60)
E/AndroidRuntime(11569): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/AndroidRuntime(11569): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/AndroidRuntime(11569): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/AndroidRuntime(11569): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/AndroidRuntime(11569): at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(11569): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(11569): at android.os.Looper.loop(Looper.java:236)
E/AndroidRuntime(11569): at android.app.ActivityThread.main(ActivityThread.java:8097)
E/AndroidRuntime(11569): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11569): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
E/AndroidRuntime(11569): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
解决办法:这里需要修改为引入3D地图。
②、配置权限(AndroidManifest.xml)
<!--允许访问网络,必选权限-->
<uses-permission android:name="android.permission.INTERNET" />
<!--允许获取精确位置,精准定位必选-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!--允许获取粗略位置,粗略定位必选-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!--允许获取设备和运营商信息,用于问题排查和网络定位(无gps情况下的定位),若需网络定位功能则必选-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!--允许获取网络状态,用于网络定位(无gps情况下的定位),若需网络定位功能则必选-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--允许获取wifi网络信息,用于网络定位(无gps情况下的定位),若需网络定位功能则必选-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!--允许获取wifi状态改变,用于网络定位(无gps情况下的定位),若需网络定位功能则必选-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!--后台获取位置信息,若需后台定位则必选-->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!--用于申请调用A-GPS模块,卫星定位加速-->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<!--允许写设备缓存,用于问题排查-->
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<!--允许写入扩展存储,用于写入缓存定位数据-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--允许读设备等信息,用于问题排查-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
③、 配置定位Service(AndroidManifest.xml)
<!-- 配置定位Service -->
<service android:name="com.amap.api.location.APSService"/>
④、实现基础地图
import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:flutter/cupertino.dart';
import '../../map/const_config.dart';
/*政府端
* 实时监控*/
class GovernmentMonitorPage extends StatefulWidget{
State<StatefulWidget> createState() =>GovernmentMonitorState();
}
class GovernmentMonitorState extends State<GovernmentMonitorPage>{
AMapController? _mapController;
Widget build(BuildContext context) {
///使用默认属性创建一个地图
final AMapWidget map = AMapWidget(
privacyStatement: ConstConfig.amapPrivacyStatement,
apiKey: ConstConfig.amapApiKeys,
onMapCreated: onMapCreated,
);
return Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
// child: Text('11'),
child: map,
);
}
void onMapCreated(AMapController controller) {
setState(() {
_mapController = controller;
getApprovalNumber();
});
}
// 获取审图号
void getApprovalNumber() async {
//普通地图审图号
String? mapContentApprovalNumber =
await _mapController?.getMapContentApprovalNumber();
//卫星地图审图号
String? satelliteImageApprovalNumber =
await _mapController?.getSatelliteImageApprovalNumber();
}
}
ConstConfig.dart:
import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:amap_flutter_map/amap_flutter_map.dart';
class ConstConfig {
///配置您申请的apikey,在此处配置之后,可以在初始化[AMapWidget]时,通过`apiKey`属性设置
///
///注意:使用[AMapWidget]的`apiKey`属性设置的key的优先级高于通过Native配置key的优先级,
///使用[AMapWidget]的`apiKey`属性配置后Native配置的key将失效,请根据实际情况选择使用
static const AMapApiKey amapApiKeys = AMapApiKey(
androidKey: '您申请的Andriod平台的key',
iosKey: '您申请的iOS平台的key');
///高德隐私合规声明,这里只是示例,实际使用中请按照实际参数设置[AMapPrivacyStatement]的'hasContains''hasShow''hasAgree'这三个参数
///
/// 注意:[AMapPrivacyStatement]的'hasContains''hasShow''hasAgree'这三个参数中有一个为false,高德SDK均不会工作,会造成地图白屏等现象
///
/// 高德开发者合规指南请参考:https://lbs.amap.com/agreement/compliance
///
/// 高德SDK合规使用方案请参考:https://lbs.amap.com/news/sdkhgsy
static const AMapPrivacyStatement amapPrivacyStatement =
AMapPrivacyStatement(hasContains: true, hasShow: true, hasAgree: true);
}
效果: