当前位置:网站首页>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);
}
}
边栏推荐
- Dp83848+ network cable hot plug
- CRS-4013: This command is not supported in a single-node configuration.
- Utiliser des unités de mesure dans votre code pour une vie meilleure
- 沃博联结束战略评估,决定保留表现优异的博姿业务
- 6-5 vulnerability exploitation SSH weak password cracking and utilization
- Senior developers tell you, how to write excellent code?
- MySQL indexes and transactions
- Developing mqtt access program under QT
- 疫情远程办公经验分享| 社区征文
- 优秀的测试/开发程序员是怎么修炼的?该往哪走......
猜你喜欢

MySQL JDBC编程
![[wechat applet] good looking carousel map component](/img/66/4ae6a72fff419c7ed1ca015eb94c03.jpg)
[wechat applet] good looking carousel map component
![[security attack and Defense] how much do you know about serialization and deserialization?](/img/cd/cc7d53b818e9a45dec22eada11bb24.png)
[security attack and Defense] how much do you know about serialization and deserialization?

RPC Technology

通过dd创建asm disk

Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file

Kivy教程之 更改背景颜色(教程含源码)

Redis: order collection Zset type data operation command

戳气球和布尔运算问题(巨难)

在代碼中使用度量單比特,從而生活更美好
随机推荐
Technology Management - learning / practice
EIG在智利推出可再生能源平台Grupo Cerro
拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
Distributed cap theory
十字路口通行优先权,十字路口通行规则图解
Niuke Xiaobai monthly race 49
Redis: hash type data operation command
B. All Distinct
RPC - grpc simple demo - learn / practice
rac删除损坏的磁盘组
First knowledge of batch processing
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
Leetcode 121 best time to buy and sell stock (simple)
CRS-4013: This command is not supported in a single-node configuration.
Utiliser des unités de mesure dans votre code pour une vie meilleure
Drozer tool
[cloud native] those lines of code that look awesome but have a very simple principle
A beautiful API document generation tool
深入解析结构化异常处理(SEH) - by Matt Pietrek
Kivy教程之 07 组件和属性绑定实现按钮button点击修改label组件(教程含源码)