English Document | 中文文档 |
---|
Plugin | Pub | Points | Popularity | Likes |
---|---|---|---|---|
ai_amap |
iOS-map | Android-map |
---|---|
:- | :- |
web-map |
---|
:- |
使用当前包作为依赖库
在文件 'pubspec.yaml' 中添加
Plugin | Pub | Points | Popularity | Likes |
---|---|---|---|---|
ai_amap |
dependencies:
ai_amap: ^version
或者以下方式依赖
dependencies:
# ai_amap package.
ai_amap:
git:
url: https://github.com/pdliuw/ai_amap.git
你可以通过下面的命令行来安装此库
$ flutter pub get
你也可以通过项目开发工具通过可视化操作来执行上述步骤
现在,在你的Dart编辑代码中,你可以使用:
import 'package:ai_amap/ai_amap.dart';
使用'地图'需要动态申请权限,动态权限推荐:permission_handler
配置权限
Android
<!--
地图SDK(包含其搜索功能)需要的基础权限
-->
<!--允许程序打开网络套接字-->
<uses-permission android:name="android.permission.INTERNET" />
<!--允许程序设置内置sd卡的写权限-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--允许程序获取网络状态-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--允许程序访问WiFi网络信息-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!--允许程序读写手机状态和身份-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!--允许程序访问CellID或WiFi热点来获取粗略的位置-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!--
地图定位需要的权限
-->
<!--用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!--用于访问GPS定位-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!--用于获取运营商信息,用于支持提供运营商信息相关的接口-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--用于访问wifi网络信息,wifi信息会用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!--用于获取wifi的获取权限,wifi信息会用来进行网络定位-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<!--用于访问网络,网络定位需要上网-->
<uses-permission android:name="android.permission.INTERNET"/>
<!--用于读取手机当前的状态-->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<!--用于写入缓存数据到扩展存储卡-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!--用于申请调用A-GPS模块-->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<!--
导航所需权限
-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application>
...
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="${apiKey}" />
<!--
https://lbs.amap.com/api/android-location-sdk/guide/android-location/getlocation
(请在application标签中声明service组件,每个app拥有自己单独的定位service。)
-->
<service android:name="com.amap.api.location.APSService"></service>
<!--
地图导航组件
-->
<activity android:name="com.amap.api.navi.AmapRouteActivity"
android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="orientation|keyboardHidden|screenSize" />
</application>
iOS
<key>NSFileProviderPresenceUsageDescription</key>
<string>使用时允许访问文件</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>始终允许定位(提高后台定位准确率)</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>使用时始终允许定位</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>使用时允许定位</string>
** 为提高iOS定位成功率,请打开-->'Background Modes' --> 勾选☑ ️'Location Updates' **
iOS支持PlatformView配置:
<key>io.flutter.embedded_views_preview</key>
<true/>
web
<script src="https://webapi.amap.com/loader.js" type="text/javascript"></script>
-
完善的封装组件请参阅:AppLocationAddressWidget
-
相关权限的交互请参阅:main.dart
-
使用地图组件项目示例:example
-
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._locationResultCallback != null) {
widget._locationResultCallback(locationResult, isSuccess);
}
_locationAddress = locationResult.address;
});
}
},
platformViewCreatedCallback: (int id) {
setState(() {
//1、ApiKey
AiAMapLocationPlatformWidgetController.setApiKey(
apiKey: "$_yourPrimaryKey");
//2、初始化定位服务
_locationController..recreateLocationService();
_locationController.startLocation();
setState(() {
_currentState = "开始定位";
});
});
},
- 定位服务核心功能示例:map_location_page
- 相关权限的交互请参阅:main.dart
- 使用定位服务项目示例:example
@override
void initState() {
super.initState();
_locationController = AiAMapLocationController(
locationResultCallback: (result, successful) {
if (result.haveAddress()) {
_stopLocation();
setState(() {
_locationAddress = result.address;
});
}
},
);
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
//1、ApiKey
AiAMapLocationController.setApiKey(
apiKey: "${GlobalConfig.AMAP_KEY}");
_startLocation();
});
}
void _startLocation() {
_locationController.startLocation();
}
void _stopLocation() {
_locationController.stopLocation();
}
- 地图模块拿来即用:AppLocationAddressWidget
- 相关权限的交互请参阅:main.dart
BSD 3-Clause License
Copyright (c) 2020, pdliuw
All rights reserved.