国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Flutter - APP跳轉(zhuǎn)高德、百度、騰訊、谷歌地圖

這篇具有很好參考價(jià)值的文章主要介紹了Flutter - APP跳轉(zhuǎn)高德、百度、騰訊、谷歌地圖。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

demo 地址: https://github.com/iotjin/jh_flutter_demo
代碼不定時(shí)更新,請(qǐng)前往github查看最新代碼

這里介紹的是不需要自己開(kāi)發(fā)地圖,直接通過(guò)給定的經(jīng)緯度,跳轉(zhuǎn)到三方地圖APP調(diào)用導(dǎo)航的方式
一種是寫(xiě)的工具類,一種是通過(guò)調(diào)用三方庫(kù)map_launcher實(shí)現(xiàn)的

官方文檔:

  • 跳轉(zhuǎn)高德導(dǎo)航 - 路徑規(guī)劃
    高德地圖官方文檔 - Android
    高德地圖官方文檔 - iOS

  • 跳轉(zhuǎn)高德導(dǎo)航
    高德地圖官方文檔

  • 跳轉(zhuǎn)百度導(dǎo)航 - 路徑規(guī)劃
    百度地圖官方文檔

  • 跳轉(zhuǎn)騰訊導(dǎo)航
    騰訊地圖官方文檔

參考文章:

Flutter 跳轉(zhuǎn)地圖軟件調(diào)起導(dǎo)航:百度、高德、騰訊、蘋(píng)果
Flutter 實(shí)戰(zhàn)調(diào)起三方地圖導(dǎo)航(高德、百度、騰訊、蘋(píng)果)

插件:
map_launcher
flutter_map
maps_launcher

實(shí)現(xiàn)

在 pubspec.yaml 文件中添加依賴插件:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-808571.html

  # url打開(kāi)工具 https://pub.flutter-io.cn/packages/url_launcher
  url_launcher: ^6.1.14
  # 打開(kāi)地圖工具 https://pub.flutter-io.cn/packages/map_launcher
  map_launcher: ^2.5.0+1

示例demo

///  map_jump_test_page.dart
///
///  Created by iotjin on 2023/10/16.
///  description: 跳轉(zhuǎn)三方地圖APP

import 'package:flutter/material.dart';
import 'package:map_launcher/map_launcher.dart';
import '/jh_common/utils/jh_map_utils.dart';
import '/jh_common/widgets/jh_text_list.dart';

// ignore_for_file: avoid_print

final List titleData = [
  '高德(JhMapUtils)',
  '高德2(JhMapUtils)',
  '百度(JhMapUtils)',
  '騰訊(JhMapUtils)',
  '三方庫(kù)跳轉(zhuǎn)高德(map_launcher)',
  '三方庫(kù)彈出地圖列表(map_launcher)',
];

class MapJumpTestPage extends StatefulWidget {
  const MapJumpTestPage({Key? key}) : super(key: key);

  
  State<MapJumpTestPage> createState() => _MapJumpTestPageState();
}

class _MapJumpTestPageState extends State<MapJumpTestPage> {
  var latitude = 39.922869448132474;
  var longitude = 116.40748500823975;

  
  Widget build(BuildContext context) {
    return JhTextList(
      title: '跳轉(zhuǎn)三方地圖導(dǎo)航',
      dataArr: titleData,
      callBack: (index, str) {
        if (str == '高德(JhMapUtils)') {
          JhMapUtils.openAMapNavi(dLatitude: latitude, dLongitude: longitude);
        }
        if (str == '高德2(JhMapUtils)') {
          JhMapUtils.openAMapNavi2(latitude: latitude, longitude: longitude);
        }
        if (str == '百度(JhMapUtils)') {
          JhMapUtils.openBaiduMapNavi(dLatitude: latitude, dLongitude: longitude);
        }
        if (str == '騰訊(JhMapUtils)') {
          JhMapUtils.openTencentMapNavi(dLatitude: latitude, dLongitude: longitude);
        }
        if (str == '三方庫(kù)跳轉(zhuǎn)高德(map_launcher)') {
          _gotoMap();
        }
        if (str == '三方庫(kù)彈出地圖列表(map_launcher)') {
          _openMapsSheet(context);
        }
      },
    );
  }

  _gotoMap() async {
    // Get list of installed maps and launch first
    final availableMaps = await MapLauncher.installedMaps;
    print(availableMaps); // [AvailableMap { mapName: Google Maps, mapType: google }, ...]
    // [
    //   AvailableMap{
    //   mapName: GoogleMaps,
    //   mapType: google
    // },
    //   AvailableMap{
    //   mapName: Amap,
    //   mapType: amap
    // },
    //   AvailableMap{
    //   mapName: BaiduMaps,
    //   mapType: baidu
    // },
    //   AvailableMap{
    //   mapName: Tencent(QQMaps),
    //   mapType: tencent
    // }
    // ]

    // await availableMaps.first.showMarker(
    //   coords: Coords(latitude, longitude),
    //   title: "Ocean Beach",
    // );
    // await availableMaps[1].showMarker(
    //   coords: Coords(latitude, longitude),
    //   title: "Ocean Beach",
    // );

    // Check if map is installed and launch it #
    var canIn = await MapLauncher.isMapAvailable(MapType.amap);
    print('canIn: $canIn');
    if (await MapLauncher.isMapAvailable(MapType.amap) == true) {
      await MapLauncher.showMarker(
        mapType: MapType.amap,
        coords: Coords(latitude, longitude),
        title: 'title',
        description: 'description',
      );
    }
  }

  _openMapsSheet(context) async {
    try {
      const title = "Ocean Beach";
      final availableMaps = await MapLauncher.installedMaps;

      showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return SafeArea(
            child: SingleChildScrollView(
              child: Wrap(
                children: <Widget>[
                  for (var map in availableMaps)
                    ListTile(
                      onTap: () => map.showMarker(coords: Coords(latitude, longitude), title: title),
                      title: Text(map.mapName),
                      leading: const Icon(Icons.map, size: 30),
                    ),
                ],
              ),
            ),
          );
        },
      );
    } catch (e) {
      print(e);
    }
  }
}

jh_map_utils實(shí)現(xiàn)代碼

///  jh_map_utils.dart
///
///  Created by iotjin on 2023/05/06.
///  description:

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'jh_device_utils.dart';

class JhMapUtils {
  /// 跳轉(zhuǎn)其他App
  static Future<void> jumpApp({String? url, String message = '跳轉(zhuǎn)失??!'}) async {
    final Uri uri = Uri.parse(url ?? '');
    if (await canLaunchUrl(uri)) {
      await launchUrl(uri);
    } else {
      debugPrint(message);
      // JhProgressHUD.showText(message);
    }
  }

  /// 判斷地圖是否有安裝
  static Future<bool> isInstallMap(String url) async {
    // var url = Uri.parse(Uri.encodeFull(url));
    final Uri uri = Uri.parse(url);
    bool canLaunch = await canLaunchUrl(uri);
    debugPrint('canLaunch: $canLaunch');
    return canLaunchUrl(uri);
  }

  /// 跳轉(zhuǎn)高德導(dǎo)航 - 路徑規(guī)劃
  /// 高德地圖官方文檔 - Android: https://lbs.amap.com/api/amap-mobile/guide/android/route
  /// 高德地圖官方文檔 - iOS: https://lbs.amap.com/api/amap-mobile/guide/ios/route
  static void openAMapNavi({
    double? sLatitude, // 起點(diǎn)緯度
    double? sLongitude, // 起點(diǎn)經(jīng)度
    String sName = '', // 起點(diǎn)名稱
    required double dLatitude, // 終點(diǎn)緯度
    required double dLongitude, // 終點(diǎn)經(jīng)度
    String dName = '', // 終點(diǎn)名稱
    String dev = '0', // 起終點(diǎn)是否偏移。0:lat和lon是已經(jīng)加密后的,不需要國(guó)測(cè)加密;1:需要國(guó)測(cè)加密,可為空,但起點(diǎn)或終點(diǎn)不為空時(shí),不能為空
    String t = '0', // t = 0 駕車;    t = 1 公交;    t = 2 步行;    t = 3 騎行(騎行僅在V788以上版本支持)
    String message = '您沒(méi)有安裝高德地圖,請(qǐng)先安裝高德地圖!',
  }) async {
    if (!JhDeviceUtils.isMobile) {
      return;
    }
    var type = JhDeviceUtils.isIOS ? 'iosamap://path?sourceApplication=applicationName&' : 'amapuri://route/plan/?';
    var url =
        '${type}sid=&slat=${sLatitude ?? ''}&slon=${sLongitude ?? ''}&sname=$sName&dlat=$dLatitude&dlon=$dLongitude&dname=$dName&dev=$dev&t=$t';
    // if (!(await canLaunchUrl(Uri.parse(url)))) {
    //   debugPrint(message);
    //   // JhProgressHUD.showText(message);
    //   return;
    // }
    await launchUrl(Uri.parse(url));
  }

  /// 跳轉(zhuǎn)高德導(dǎo)航
  /// 高德地圖官方文檔: https://lbs.amap.com/api/amap-mobile/guide/android/navigation
  static void openAMapNavi2({
    required double latitude,
    required double longitude,
    String poiName = '',
    String dev = '0', // 是否偏移(0:lat 和 lon 是已經(jīng)加密后的,不需要國(guó)測(cè)加密; 1:需要國(guó)測(cè)加密)
    String message = '您沒(méi)有安裝高德地圖,請(qǐng)先安裝高德地圖!',
  }) async {
    var device = JhDeviceUtils.isAndroid ? 'android' : 'ios';
    var url = '${device}amap://navi?sourceApplication=amap&poiname=$poiName&lat=$latitude&lon=$longitude&dev=$dev';
    // if (!(await canLaunchUrl(Uri.parse(url)))) {
    //   debugPrint(message);
    //   // JhProgressHUD.showText(message);
    //   return;
    // }
    await launchUrl(Uri.parse(url));
  }

  /// 跳轉(zhuǎn)百度導(dǎo)航 - 路徑規(guī)劃
  /// 百度地圖官方文檔: https://lbsyun.baidu.com/index.php?title=uri/api/android
  static void openBaiduMapNavi({
    double? sLatitude, // 起點(diǎn)緯度
    double? sLongitude, // 起點(diǎn)經(jīng)度
    String sName = '', // 起點(diǎn)名稱
    required double dLatitude, // 終點(diǎn)緯度
    required double dLongitude, // 終點(diǎn)經(jīng)度
    String dName = '', // 終點(diǎn)名稱
    String mode = 'driving', // 導(dǎo)航模式,可選transit(公交)、driving(駕車)、walking(步行)和riding(騎行)默認(rèn):driving
    String coordType =
        'gcj02', // 坐標(biāo)類型,必選參數(shù)。coord_type= bd09ll 允許的值為:bd09ll(百度經(jīng)緯度坐標(biāo)) bd09mc(百度墨卡托坐標(biāo)) gcj02(經(jīng)國(guó)測(cè)局加密的坐標(biāo)) wgs84(gps獲取的原始坐標(biāo))
    String message = '您沒(méi)有安裝百度地圖,請(qǐng)先安裝百度地圖!',
  }) async {
    var url =
        'baidumap://map/direction?origin=name:$sName|latlng:$sLatitude,$sLongitude&destination=name:$dName|latlng:$dLatitude,$dLongitude&mode=$mode&coord_type=$coordType';
    // if (!(await canLaunchUrl(Uri.parse(url)))) {
    //   debugPrint(message);
    //   // JhProgressHUD.showText(message);
    //   return;
    // }
    await launchUrl(Uri.parse(url));
  }

  /// 跳轉(zhuǎn)騰訊導(dǎo)航
  /// 騰訊地圖官方文檔: https://lbs.qq.com/webApi/uriV1/uriGuide/uriMobileRoute
  static void openTencentMapNavi({
    double? sLatitude, // 起點(diǎn)緯度
    double? sLongitude, // 起點(diǎn)經(jīng)度
    String sName = '', // 起點(diǎn)名稱
    required double dLatitude, // 終點(diǎn)緯度
    required double dLongitude, // 終點(diǎn)經(jīng)度
    String dName = '', // 終點(diǎn)名稱
    String type = 'drive', // 路線規(guī)劃方式參數(shù):  公交:bus  駕車:drive  步行:walk  騎行:bike
    String referer = 'OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77', // 請(qǐng)?zhí)顚?xiě)開(kāi)發(fā)者key,
    String message = '您沒(méi)有安裝騰訊地圖,請(qǐng)先安裝騰訊地圖!',
  }) async {
    // 起點(diǎn)坐標(biāo),格式:lat,lng (緯度在前,經(jīng)度在后,逗號(hào)分隔)  功能參數(shù)值:CurrentLocation :使用定位點(diǎn)作為起點(diǎn)坐標(biāo)
    var formInfo = (sLatitude == null || sLongitude == null)
        ? 'from=$sName&CurrentLocation'
        : 'from=$sName&fromcoord=$sLatitude,$sLongitude';
    var url = 'qqmap://map/routeplan?type=$type&${formInfo}&to=$dName&tocoord=$dLatitude,$dLongitude&referer=$referer';
    // if (!(await canLaunchUrl(Uri.parse(url)))) {
    //   debugPrint(message);
    //   // JhProgressHUD.showText(message);
    //   return;
    // }
    await launchUrl(Uri.parse(url));
  }

  static const double earthRadius = 6378.137; //地球半徑

  //計(jì)算兩點(diǎn)間距離
  static double distance(double lat1, double lng1, double lat2, double lng2) {
    double radLat1 = _rad(lat1);
    double radLat2 = _rad(lat2);
    double a = radLat1 - radLat2;
    double b = _rad(lng1) - _rad(lng2);
    double s = 2 * asin(sqrt(pow(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) * pow(sin(b / 2), 2)));
    s *= earthRadius;
    s = (s * 10000).round() / 10000;
    return s;
  }

  static double _rad(double d) {
    return d * pi / 180.0; //角度轉(zhuǎn)換成弧度
  }
}

到了這里,關(guān)于Flutter - APP跳轉(zhuǎn)高德、百度、騰訊、谷歌地圖的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 微信小程序?qū)W習(xí)實(shí)錄5(H5嵌入小程序、map組件、地圖調(diào)起功能、騰訊百度高德導(dǎo)航頁(yè)、返回web-view頁(yè))

    微信小程序?qū)W習(xí)實(shí)錄5(H5嵌入小程序、map組件、地圖調(diào)起功能、騰訊百度高德導(dǎo)航頁(yè)、返回web-view頁(yè))

    創(chuàng)建容器 地圖家長(zhǎng) 在H5頁(yè)面引入 //res.wx.qq.com/open/js/jweixin-1.6.0.js ,建議使用高版本; 點(diǎn)擊返回按鈕 調(diào)用微信小程序和H5通用API 判斷是否在微信小程序環(huán)境中 地圖調(diào)起,再次返回小程序頁(yè) 獲取H5傳遞參數(shù)的方式為: console.log(options) latitude和longitude必須為數(shù)字類型,不支持字符

    2024年02月07日
    瀏覽(98)
  • 高德地圖與百度地圖坐標(biāo)相互轉(zhuǎn)化

    1. WGS-84原始坐標(biāo)系 ,一般用國(guó)際GPS紀(jì)錄儀記錄下來(lái)的經(jīng)緯度,通過(guò)GPS定位拿到的原始經(jīng)緯度,Google和高德地圖定位的的經(jīng)緯度(國(guó)外)都是基于WGS-84坐標(biāo)系的;但是在國(guó)內(nèi)是不允許直接用WGS84坐標(biāo)系標(biāo)注的,必須經(jīng)過(guò)加密后才能使用; 2. GCJ-02坐標(biāo)系 ,又名“火星坐標(biāo)系

    2024年02月16日
    瀏覽(28)
  • 微信小程序騰訊地圖定位轉(zhuǎn)高德地圖定位

    微信小程序獲取到了當(dāng)前用戶的定位,需要在高德地圖上進(jìn)行渲染。 發(fā)現(xiàn)正常渲染后,偏差幾百米。 這里圖方便,直接丟到window上了 這里演示“騰訊地圖”轉(zhuǎn)“高德地圖”

    2024年01月25日
    瀏覽(122)
  • 高德百度騰訊之間經(jīng)緯度的轉(zhuǎn)換

    高德百度騰訊之間經(jīng)緯度的轉(zhuǎn)換

    提示:這里可以添加本文要記錄的大概內(nèi)容: 提示:以下是本篇文章正文內(nèi)容,下面案例可供參考 百度地圖: 高德地圖: 騰訊地圖 最后轉(zhuǎn)換結(jié)果 可知,高德和騰訊使用的編碼方式是一樣的,所以最后轉(zhuǎn)換的經(jīng)緯度基本一樣

    2024年02月13日
    瀏覽(24)
  • flutter高德地圖大頭針

    flutter高德地圖大頭針

    1、效果圖 2、pub get #地圖定位 amap_flutter_map: ^3.0.0 amap_flutter_location: ^3.0.0 3、上代碼

    2024年02月11日
    瀏覽(30)
  • 小程序引入高德/百度地圖坐標(biāo)系詳解

    小程序引入高德/百度地圖坐標(biāo)系詳解

    官網(wǎng)最近更新時(shí)間:最后更新時(shí)間: 2021年08月17日 高德官網(wǎng)之在原生小程序中使用的常見(jiàn)問(wèn)題 鏈接 目前在小程序中使用 高德地圖只支持以下功能 :地址描述、POI 和實(shí)時(shí)天氣數(shù)據(jù) 小結(jié):從高德api中獲取數(shù)據(jù)然后更新到騰訊地圖的map上 其實(shí)還是使用的騰訊地圖 只不過(guò)數(shù)據(jù)的來(lái)

    2024年02月09日
    瀏覽(23)
  • 高德地圖H5內(nèi)嵌小程序遇到的跳轉(zhuǎn)地圖問(wèn)題

    高德地圖H5內(nèi)嵌小程序遇到的跳轉(zhuǎn)地圖問(wèn)題

    h5中的地圖是這樣展示的,在微信小程序是無(wú)法跳轉(zhuǎn)的 引入jweixin.js vue里判斷 在小程序這邊接收傳過(guò)來(lái)的參數(shù)(需要注意的是:高德地圖坐標(biāo)和騰訊坐標(biāo)是一樣的,只需要經(jīng)緯度反過(guò)來(lái)即可) 最后在小程序中呈現(xiàn)是這樣,就完美實(shí)現(xiàn)了

    2024年02月11日
    瀏覽(19)
  • flutter實(shí)現(xiàn)調(diào)用原生安卓的高德地圖導(dǎo)航功能(插件化)

    flutter實(shí)現(xiàn)調(diào)用原生安卓的高德地圖導(dǎo)航功能(插件化)

    查看了高德地圖flutter插件的文檔,都沒(méi)有能支持導(dǎo)航的功能,并且flutter的高德插件支持的功能特別少,沒(méi)辦法,只能使用安卓原生的導(dǎo)航,flutter去調(diào)用了,具體實(shí)現(xiàn)方式如下: 創(chuàng)建 Flutter 插件 使用--template=plugin 聲明創(chuàng)建的是同時(shí)包含了 iOS 和 Android 代碼的 plugin; 使用--o

    2024年02月16日
    瀏覽(20)
  • uniapp App端使用高德地圖

    uniapp App端使用高德地圖

    uniapp App端使用高德地圖 先去高德官網(wǎng)申請(qǐng)keyhttps://console.amap.com/dev/key/app 關(guān)于SHA1生成方法如下:https://lbs.amap.com/faq/android/map-sdk/create-project/43112 我使用的是使用 keytool(jdk自帶工具)獲取SHA1 PackageName包名和你需要云打包的項(xiàng)目Android包名一樣 打開(kāi)項(xiàng)目manifest.json文件,將所需的

    2024年02月05日
    瀏覽(93)
  • uniapp 開(kāi)發(fā)安卓App實(shí)現(xiàn)高德地圖路線規(guī)劃導(dǎo)航

    uniapp 開(kāi)發(fā)安卓App實(shí)現(xiàn)高德地圖路線規(guī)劃導(dǎo)航

    描述這個(gè)技術(shù)是做什么的/什么情況下會(huì)使用到這個(gè)技術(shù),學(xué)習(xí)該技術(shù)的原因,技術(shù)的難點(diǎn)在哪里??刂圃?0-100字內(nèi)。 uniapp的map組件中導(dǎo)航路線的展示。是uniapp開(kāi)發(fā)app時(shí)引入地圖導(dǎo)航的實(shí)現(xiàn)方式。技術(shù)難點(diǎn)在于實(shí)現(xiàn)map組件時(shí)對(duì)于屬性以及函數(shù)的細(xì)節(jié)使用很容易出現(xiàn)一些奇怪的

    2024年02月01日
    瀏覽(28)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包