当前位置:网站首页>Flutter 调用高德地图APP实现位置搜索、路线规划、逆地理编码
Flutter 调用高德地图APP实现位置搜索、路线规划、逆地理编码
2022-07-04 03:55:00 【早起的年轻人】
1 开发准备
pubspec.yaml 配置文件中添加插件
dependencies:
flutter:
sdk: flutter
url_launcher: ^6.1.2
iOS 配置 info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>iosamap</string>
<string>baidumap</string>
</array>
2 Flutter 调起高德地图 - 搜索位置 逆地理编码
static Future<bool> openAmap(
double longitude,
double latitude, {
String? address,
String? title,
bool showErr = true,
}) async {
String url =
'${
Platform.isAndroid ? 'android' : 'ios'}amap://viewReGeo?sourceApplication=${
title??""}&lat=$latitude&lon=$longitude&dev=0';
if (Platform.isIOS) url = Uri.encodeFull(url);
try {
if (await canLaunchUrlString(url)) {
await launchUrlString(url);
return true;
} else {
if (showErr) showToastCommon('无法调起高德地图');
return false;
}
} on Exception catch (e) {
if (showErr) showToastCommon('无法调起高德地图');
return false;
}
}
实际上是调用的高德地图开放api 反向地址解析
调起的结果如下 :
3 坐标类型选择
需要注意的是 dev 坐标类型的取值
- 0 使用经纬度是已经加密后的,不需要国测加密;
- 1 使用经纬度是未加密的,需要国测加密;
如果不传递正确的坐标类型参数,会导致地点坐标位置偏移。默认为bd09经纬度坐标。
4 Flutter 调起高德地图 - 导航 路线规划
/// 高德地图调用 导航
static Future<bool> openAmapNav(
double longitude,
double latitude, {
String? address,
bool showErr = true,
}) async {
String url =
'${
Platform.isAndroid ? 'android' : 'ios'}amap://navi?sourceApplication=amap&lat=$latitude&lon=$longitude&dev=0&style=2&poiname=${
address ?? ''}';
if (Platform.isIOS) url = Uri.encodeFull(url);
try {
if (await canLaunchUrlString(url)) {
await launchUrlString(url);
return true;
} else {
if (showErr) showToastCommon('无法调起高德地图');
return false;
}
} on Exception catch (e) {
if (showErr) showToastCommon('无法调起高德地图');
return false;
}
}
实际上是调用的
5 提示框使用的是 GetX 框架
static showToastCommon(String message) {
Get.defaultDialog(
title: "提示",
middleText: message,
backgroundColor: Colors.white,
titleStyle: const TextStyle(color: Colors.black),
middleTextStyle: const TextStyle(color: Colors.red),
textConfirm: "知道了",
confirmTextColor: Colors.white,
onConfirm: () {
Get.back();
},
radius: 8);
}
}
边栏推荐
- Precautions for accompanying driving these 23 points should be paid attention to!
- Leetcode 121 best time to buy and sell stock (simple)
- Kivy教程之 自定义字体(教程含源码)
- MySQL JDBC编程
- MIN_ RTO dialog
- Definition of DCDC power supply current
- 5张图告诉你:同样是职场人,差距怎么这么大?
- Binary search tree
- Qt QTableView数据列宽度自适应
- Redis: operation command for collecting set type data
猜你喜欢
随机推荐
Wobo Union ended its strategic evaluation and decided to retain Bozi's business with excellent performance
Statistical genetics: Chapter 3, population genetics
Sample template of software design document - learning / practice
RPC - gRPC简单的demo - 学习/实践
旭化成首次参展第五届中国国际进口博览会(5th CIIE)
Definition of DCDC power supply current
优秀的测试/开发程序员是怎么修炼的?该往哪走......
Create ASM disk through DD
RPC Technology
PaddleHub人脸识别方案部署,将训练好的模型在pytchrom中进行部署应用
Balloon punching and Boolean operation problems (extremely difficult)
测试 CS4344 立体声DA转换器
红队视角下的防御体系突破之第二篇案例分析
LeetCode136+128+152+148
Technology Management - learning / practice
Graduation project
DCDC电源电流定义
Talking about what a high-quality little red book copy needs to have
附件六:防守工作简报.docx
Network - vxlan




![leetcode:1314. Matrix area and [2D prefix and template]](/img/b4/2c9e66c8eafe1db2a3d07e861494e0.png)



