ai_amap

Creator: coderz1093

Last updated:

0 purchases

ai_amap Image
ai_amap Images

Languages

Categories

Add to Cart

Description:

ai amap

ai_amap #





English Document
中文文档






Plugin
Pub
Points
Popularity
Likes




ai_amap







Effect #



iOS-map
Android-map














web-map










1.安装 #
使用当前包作为依赖库
1. 依赖此库 #
在文件 'pubspec.yaml' 中添加



Plugin
Pub
Points
Popularity
Likes




ai_amap








dependencies:

ai_amap: ^version

copied to clipboard
或者以下方式依赖
dependencies:

# ai_amap package.
ai_amap:
git:
url: https://github.com/pdliuw/ai_amap.git

copied to clipboard
2. 安装此库 #
你可以通过下面的命令行来安装此库

$ flutter pub get


copied to clipboard
你也可以通过项目开发工具通过可视化操作来执行上述步骤
3. 导入此库 #
现在,在你的Dart编辑代码中,你可以使用:

import 'package:ai_amap/ai_amap.dart';

copied to clipboard
2.使用 #
使用'地图'需要动态申请权限,动态权限推荐: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>

copied to clipboard


iOS

<key>NSFileProviderPresenceUsageDescription</key>
<string>使用时允许访问文件</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>始终允许定位(提高后台定位准确率)</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>使用时始终允许定位</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>使用时允许定位</string>


copied to clipboard
** 为提高iOS定位成功率,请打开-->'Background Modes' --> 勾选☑ ️'Location Updates' **
iOS支持PlatformView配置:

<key>io.flutter.embedded_views_preview</key>
<true/>

copied to clipboard


web

<script src="https://webapi.amap.com/loader.js" type="text/javascript"></script>


copied to clipboard

1.使用'地图组件'的地方中: #


完善的封装组件请参阅:AppLocationAddressWidget


相关权限的交互请参阅:main.dart


使用地图组件项目示例:example


1、使用地图Widget


//map widget
_aMapWidget = AiAMapLocationPlatformWidget(
platformWidgetController: _locationController,
);

copied to clipboard

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 = "开始定位";
});
});
},

copied to clipboard
2.使用'定位服务'的地方中: #

定位服务核心功能示例: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();

}


copied to clipboard

地图模块拿来即用:AppLocationAddressWidget
相关权限的交互请参阅:main.dart

LICENSE #
BSD 3-Clause License

Copyright (c) 2020, pdliuw
All rights reserved.
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.