当前位置:网站首页>Flutter 调用百度地图APP实现位置搜索、路线规划
Flutter 调用百度地图APP实现位置搜索、路线规划
2022-06-29 18:45: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> openBaiduMap(
double longitude,
double latitude, {
String? address,
bool showErr = true,
String? title,
}) async {
String url =
"bdapp://map/geocoder?location=$latitude,$longitude&src=$title&coord_type=gcj02";
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 坐标类型选择
需要注意的是 coord_type 坐标类型的取值
- bd09ll(百度经纬度坐标)
- bd09mc(百度墨卡托坐标)
- gcj02(经国测局加密的坐标)
- wgs84(gps获取的原始坐标)
如果不传递正确的坐标类型参数,会导致地点坐标位置偏移。默认为bd09经纬度坐标。
4 Flutter 调起百度地图 - 导航 路线规划
static Future<bool> openBaiduMapNav(
double longitude,
double latitude, {
String? address,
bool showErr = true,
String? title,
}) async {
String url =
'baidumap://map/direction?destination=name:${
address ?? ''}|latlng:$latitude,$longitude&coord_type=bd09ll&mode=driving';
if (Platform.isIOS) url = Uri.encodeFull(url);
try {
if (await canLaunchUrlString(url)) {
await launchUrlString(url);
}
} on Exception catch (e) {
if (showErr) showToastCommon('无法调起百度地图');
return false;
}
return true;
}
实际上是调用的
边栏推荐
- The 8th "Internet +" competition - cloud native track invites you to challenge
- Understanding of strong caching and negotiation caching
- Anaconda installs and configures jupyter notebook remote
- Page object and data driven test
- 防汛救援便携式应急通信系统解决方案
- The sales volume could not catch up with the speed of taking money. Weima went to Hong Kong for emergency rescue
- Introduction to isalpha () method
- 数据库是什么?数据库详细笔记!带你走进数据库~你想知道的这里都有!
- 74. maximum profit on shares
- Third party tools and framework integration
猜你喜欢

Cantata 9.5版本已正式通过SGS-TÜV认证,符合所有主要软件安全标准

AI场景存储优化:云知声超算平台基于 JuiceFS 的存储实践

ChainSafe跨链桥部署教程

面霸篇:MySQL六十六问,两万字+五十图详解!

数据仓库模型分层ODS、DWD、DWM实战

Understanding of strong caching and negotiation caching

使用 OpenCV 的基于标记的增强现实

Point, line, surface and body of enterprise digital transformation!
![[Nanjing University] information sharing of the first and second postgraduate entrance examinations](/img/0d/a6392e6b92bb689e90c038ffac9dd8.jpg)
[Nanjing University] information sharing of the first and second postgraduate entrance examinations

企业数字化转型的点、线、面、体!
随机推荐
MariaDB的安装与配置
TP5 where queries whether a field in the database contains a value. Fuzzy queries are performed without the like method
PHP implementation of sorting two-dimensional arrays by specified key names
小米笔试真题一
Dragon canvas animation
C Primer Plus 第12章_存储类别、链接和内存管理_代码和练习题
Selenium WebDriver的高级特性
【日常训练】535. TinyURL 的加密与解密
从CIO到顾问:IT领导者的转型之路
JS converts seconds to "2h30min50s" format
炒股用同花顺开户交易安全吗?
Data analysis time series prediction
Deep learning --- the weight of the three good students' scores (2)
MySQL 企业级开发规范
tp5 where查询数据库中的某个字段是否包含某个值,不用like的方法,模糊查询
2. add customized related files to the keil5 project established by stm32cubemx
Hello, do you have any official website samples for MySQL CDC, PostgreSQL CDC? Give me a link to learn
Usage of BeanUtils property replication
76. nearest common ancestor of binary tree
【笔记】再笔记--边干边学Verilog HDL – 014