当前位置:网站首页>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);
}
}
边栏推荐
- 分布式CAP理论
- 6-5漏洞利用-SSH弱口令破解利用
- Virtual commodity account trading platform source code_ Support personal QR code collection
- 疫情远程办公经验分享| 社区征文
- Definition of DCDC power supply current
- Drozer tool
- Intersection traffic priority, illustration of intersection traffic rules
- MIN_RTO 对话
- MySQL indexes and transactions
- Deep understanding of redis -- bloomfilter
猜你喜欢

Redis: operation command for collecting set type data

Longest increasing subsequence problem (do you really know it)

Many founders of technology companies provided enterpriser first with a round C financing of up to US $158million to help it invest in the next generation of global innovators

分布式CAP理论

多位科技公司创始人向Entrepreneur First提供高达1.58亿美元的C轮融资,协助其投资下一代全球创新者

【愚公系列】2022年7月 Go教学课程 001-Go语言前提简介

Change the background color of Kivy tutorial (tutorial includes source code)

20000 words will take you to master multithreading

Main applications of TDK lambda power supply

【安全攻防】序列化与反序列,你了解多少?
随机推荐
Graduation project
Many founders of technology companies provided enterpriser first with a round C financing of up to US $158million to help it invest in the next generation of global innovators
郑州正清园文化传播有限公司:针对小企业的7种营销技巧
ADB tools
Distributed cap theory
YoloV6实战:手把手教你使用Yolov6进行物体检测(附数据集)
Unity Resource path
牛客小白月赛49
Change the background color of Kivy tutorial (tutorial includes source code)
6-4漏洞利用-SSH Banner信息获取
Deep understanding of redis -- bloomfilter
Kivy教程之 更改背景颜色(教程含源码)
EIG在智利推出可再生能源平台Grupo Cerro
5张图告诉你:同样是职场人,差距怎么这么大?
Select function variable column name in dplyr of R language
[go] database framework Gorm
Dp83848+ network cable hot plug
Annexe VI: exposé sur les travaux de défense. Docx
PaddleHub人脸识别方案部署,将训练好的模型在pytchrom中进行部署应用
旭化成首次参展第五届中国国际进口博览会(5th CIIE)