高德2D地图插件
本插件主要服务于 flutter_deer。仅保持现有功能,没有的功能可自行拓展。
pubspec.yaml 添加:
flutter_2d_amap:
git:
url: https://github.com/simplezhli/flutter_2d_amap.git
使用前同意隐私政策:
Flutter2dAMap.updatePrivacy(true);
使用:
import 'package:flutter_2d_amap/flutter_2d_amap.dart';
AMap2DView(
onPoiSearched: (result) {
},
onAMap2DViewCreated: (controller) {
},
)
AndroidManifest.xml 中添加:
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="配置你的key"/>
如果你的targetSdkVersion
为27以上,则需要做以下配置来支持http明文请求(具体可以看demo),否则会导致地图加载不出:
AndroidManifest.xml 中添加:
<application
android:networkSecurityConfig="@xml/network_security_config"
/>
在 res 下新增一个 xml 目录,然后创建一个名为:network_security_config.xml
文件:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
使用前设置key:
Flutter2dAMap.setApiKey(iOSKey: '配置你的key');
在info.plist中增加:
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用,如果您需要使用后台定位功能请选择“始终允许”。</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用。</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用。</string>
<key>io.flutter.embedded_views_preview</key>
<true/>
index.html
中添加(在main.dart.js
之前):
<script src="https://webapi.amap.com/loader.js"></script>
使用前设置key:
Flutter2dAMap.setApiKey(webKey: '配置你的key');
Copyright 2019 simplezhli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.