ai_amap
原创文章,侵权必究!如若转载,请务必联系作者,并标注来源!
totem
Effect
地图.jpg
定位.jpg
导航.jpg
导航.jpg
1.安装
使用当前包作为依赖库
1. 依赖此库
在文件 'pubspec.yaml' 中添加
dependencies:
ai_amap: ^version
或者以下方式依赖
dependencies:
# ai_amap package.
ai_amap:
git:
url: https://github.com/pdliuw/ai_amap.git
2. 安装此库
你可以通过下面的命令行来安装此库
$ flutter pub get
你也可以通过项目开发工具通过可视化操作来执行上述步骤
3. 导入此库
现在,在你的Dart编辑代码中,你可以使用:
import 'package:ai_amap/ai_amap.dart';
2.使用
使用'地图'需要动态申请权限,动态权限推荐:permission_handler
配置权限
Android
...
android:name="com.amap.api.v2.apikey"
android:value="${apiKey}" />
android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="orientation|keyboardHidden|screenSize" />
iOS
NSFileProviderPresenceUsageDescription
使用时允许访问文件
NSLocationAlwaysAndWhenInUseUsageDescription
始终允许定位(提高后台定位准确率)
NSLocationAlwaysUsageDescription
使用时始终允许定位
NSLocationWhenInUseUsageDescription
使用时允许定位
** 为提高iOS定位成功率,请打开-->'Background Modes' --> 勾选☑ ️'Location Updates' **
iOS支持PlatformView配置:
io.flutter.embedded_views_preview
1.使用'地图'的地方中:
1、使用地图Widget
//map widget
_aMapWidget = AiAMapLocationPlatformWidget(
platformWidgetController: _locationController,
);
2、使用地图Controller
_locationController = AiAMapLocationPlatformWidgetController(
locationResultCallback:
(AiAMapLocationResult locationResult, bool isSuccess) {
setState(() {
_currentState = "定位:$isSuccess";
});
if (locationResult.haveAddress()) {
_locationController.stopLocation();
setState(() {
if (widget._locationResultTest != null) {
widget._locationResultTest(locationResult, isSuccess);
}
_locationAddress = locationResult.address;
});
}
},
platformViewCreatedCallback: (int id) {
setState(() {
//1、ApiKey
AiAMapLocationPlatformWidgetController.setApiKey(
apiKey: "$_yourPrimaryKey");
//2、初始化定位服务
_locationController..recreateLocationService();
_locationController.startLocation();
setState(() {
_currentState = "开始定位";
});
});
},
flutter开发者项目示例:
flutter_app_sample 帮助flutter开发者更快入门、精进,避免不必要的技术坑。
如果您觉得此项目对您有所帮助,也可以"star"一下,我们得到您的鼓励后会更有动力持续推出更多有益于您的技术示例
特征:
本项目是主打技术示例,所以涉及到的需求会比较少,涉及到的技术会比较多
本项目是为flutter开发者专门打造的“Api demo app”
本项目不仅包含flutter 各种widget组件,还包含开发包、插件,以及与各平台platforms交互、通信(Platform Channel)的技术示例。
移步查看更多特征......