当前位置:网站首页>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;
}
实际上是调用的
边栏推荐
- Escape and March, the "two-sided Jianghu" of temporary food
- Notes on spintronics - zhangshufeng
- 销量赶不上拿钱速度,威马赴港救急
- Know that Chuangyu has helped the energy industry in asset management and was selected into the 2021 IOT demonstration project of the Ministry of industry and information technology
- 移动端测试
- Understanding of strong caching and negotiation caching
- How to use the oak camera on raspberry pie?
- Redis(一)--Redis入门(2)--Redis数据类型
- selenium的跨浏览器测试
- UnrealEngine插件中使用protobuf 链接mysql
猜你喜欢

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

MariaDB的安装与配置

76.二叉树的最近公共祖先

AMAZING PANDAVERSE:META”无国界,来2.0新征程激活时髦属性

C#_摄像头图像转换为Bitmap格式及绘制十字线

1. use stm32cubemx to establish stm32g030c8t6 project

出逃与进军,临期食品的「双面江湖」

习题8 #第8章 Verilog有限状态机设计-4 #Verilog #Quartus #modelsim

Mac: MySQL 66 questions, 20000 words + 50 pictures!

程序员值得收藏的几款代码截图美化工具播
随机推荐
PHP implementation of sorting two-dimensional arrays by specified key names
暴力解决《猜名次》问题
Redis bloom filter and cuckoo filter
The strategy of convertible bonds -- - (cake sharing, premium, forced redemption, downward revision, double low)
学习放大器至少要3年?
建立自己的网站(12)
Selenium的各类API方法
【笔记】再笔记--边干边学Verilog HDL – 014
Redis(一)--Redis入门(2)--Redis数据类型
75. nearest common ancestor of binary search tree
2. how to install MySQL database in Galaxy Kirin offline mode
MySQL 企业级开发规范
什么是多范式编程语言,其中的“多范式”是什么意思?
从CIO到顾问:IT领导者的转型之路
JS converts seconds to "2h30min50s" format
使用 OpenCV 的基于标记的增强现实
Anfulai embedded weekly report no. 271: June 20, 2022 to June 26, 2022
Interview question 10.10 Rank of digital stream
MySQL 企業級開發規範
MariaDB的安装与配置