当前位置:网站首页>Flutter calls Baidu map app to realize location search and route planning
Flutter calls Baidu map app to realize location search and route planning
2022-06-29 19:44:00 【Young people who get up early】
Aspiring climber , I will not be intoxicated by some footprints along the way , In the world of Manon , Beautiful application experience , It comes from the programmer's handling of details and the realm of self requirements , Young people are also one of the busy yard farmers , Every day 、 Once a week , Will leave some footprints , It's the content of these creations , There is a kind of persistence , I don't know why , If you are confused , Let's take a look at the path of the yard farmer .
1 The development of preparation
pubspec.yaml Add a plug-in to the configuration file
dependencies:
flutter:
sdk: flutter
url_launcher: ^6.1.2
iOS To configure info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>iosamap</string>
<string>baidumap</string>
</array>
2 Flutter Tune up Baidu map - Search location
Baidu map development document
/// Baidu Maps
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(' Unable to adjust Baidu map ');
return false;
}
} on Exception catch (e) {
if (showErr) showToastCommon(' Unable to adjust Baidu map ');
return false;
}
}
In fact, it is called Baidu map open api Reverse address resolution 
The results are as follows :
3 Coordinate type selection
It should be noted that coord_type Value of coordinate type
- bd09ll( Baidu latitude and longitude coordinates )
- bd09mc( Baidu Mercator coordinates )
- gcj02( Coordinates encrypted by the National Survey Bureau )
- wgs84(gps The original coordinates obtained )
If you do not pass the correct coordinate type parameter , It will cause the location coordinates to shift . The default is bd09 Latitude and longitude coordinates .
4 Flutter Tune up Baidu map - Navigation Route planning
Baidu map development document
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(' Unable to adjust Baidu map ');
return false;
}
return true;
}
It's actually called 
边栏推荐
猜你喜欢

The list of winners in the classic Smurfs of childhood: bluedad's digital collection was announced

La collection numérique Meng xiangshun, artiste national du tigre peint, est disponible en quantité limitée et est offerte avec Maotai de l'année du tigre

One hour to build a sample scenario sound network to release lingfalcon Internet of things cloud platform

KDD 2022 | characterization alignment and uniformity are considered in collaborative filtering

Inception 新结构 | 究竟卷积与Transformer如何结合才是最优的?

【精品】pinia详解

3-3主機發現-四層發現

3-2主机发现-三层发现

Classic illustration of K-line diagram (Collection Edition)

Win11系统小组件打不开?Win11系统小组件无法打开解决方法
随机推荐
构建增强现实移动应用程序的六款顶级工具
MSYQL, redis, mongodb visual monitoring tool grafana
Win11系统小组件打不开?Win11系统小组件无法打开解决方法
ASP. Net core creates razor page and uploads multiple files (buffer mode) (Continued)
What if the win11 policy service is disabled? Solution to disabling win11 policy service
Where is the win11 installation permission set? Win11 installation permission setting method
畫虎國手孟祥順數字藏品限量發售,隨贈虎年茅臺
剑指 Offer 59 - I. 滑动窗口的最大值
3-3主機發現-四層發現
Zotero期刊自动匹配更新影响因子
From CIO to Consultant: the transformation of it leaders
Go: how to write a correct UDP server
有了这4个安全测试工具,对软件安全测试say so easy!
swift可选值总结
Canonical engineers are trying to solve the performance problem of Firefox snap
npm ERR! fatal: early EOF npm ERR! fatal: index-pack failed
In 2022, the financial interest rate has dropped, so how to choose financial products?
【网络方向实训】-企业园区网络设计-【Had Done】
2022年理财利率都降了,那该如何选择理财产品?
Canonical的工程师们正努力解决Firefox Snap的性能问题