前期配置
在接入定位的基础上添加如下配置
在 project\android\app\build.gradle
中添加
dependencies {
...
implementation('com.amap.api:3dmap:7.7.0')
}
在 project\android\app\src\main\AndroidManifest.xml
中添加调试权限
<!--用于读取手机当前的状态-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!--用于写入缓存数据到扩展存储卡-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--允许写设备缓存,用于问题排查-->
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<!--允许读设备等信息,用于问题排查-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
安装高德地图 flutter 工具包
amap_flutter_map: ^3.0.0
示例
import 'package:flutter/material.dart';
import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:amap_flutter_base/amap_flutter_base.dart';
class MapComponent extends StatefulWidget {
const MapComponent({super.key});
@override
State<MapComponent> createState() => _MapComponentState();
}
class _MapComponentState extends State<MapComponent> {
static const AMapApiKey amapApiKeys = AMapApiKey(
androidKey: '安卓的key',
iosKey: 'ios的key'
);
void onMapCreated(AMapController controller){
(AMapController controller){
print("地图创建成功");
};
}
late AMapController _mapController;
void _onMapCreated(AMapController controller) {
_mapController = controller;
getApprovalNumber();
}
/// 获取审图号
void getApprovalNumber() async {
//普通地图审图号
String? mapContentApprovalNumber =
await _mapController?.getMapContentApprovalNumber();
//卫星地图审图号
String? satelliteImageApprovalNumber =
await _mapController?.getSatelliteImageApprovalNumber();
}
@override
Widget build(BuildContext context) {
///在创建地图时设置apiKey属性
AMapWidget map = AMapWidget(
///配置apiKey,设置为null或者不设置则优先使用native端配置的key
apiKey: amapApiKeys,
buildingsEnabled:true,// 是否显示3D建筑物
compassEnabled:true, // 指南针
scaleEnabled:true, // 比例尺
trafficEnabled:true, //显示路况
labelsEnabled:true, // 显示地图文字
onMapCreated:_onMapCreated, //初始化成功的回调
);
return Scaffold(
appBar: AppBar(title:const Text("flutter 地图可视化")),
body:Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child:map
)
);
}
}
虚拟机内无效果,需要真机查看示例