Flutter 实战调起三方地图导航(高德、百度、腾讯、苹果)

实战工具类 地图导航
注意 地图Url 需要Uri.encodeFull(url)进行编码,要不然IOS无法调起 三方导航

为何使用encodeFull见
https://blog.csdn.net/timtian008/article/details/106119072

 /// 高德地图
  static Future gotoGaoDeMap(longitude, latitude,
      {String toAddress}) async {
    List list = GpsUtil.bd09_To_Gcj02(latitude, longitude);
    var url =
        '${Platform.isAndroid ? 'android' : 'ios'}amap://navi?sourceApplication=amap&lat=${list[0]}&lon=${list[1]}&dev=0&style=2&poiname=${toAddress ?? ''}';
    url=Uri.encodeFull(url);
    print('gotoGaoDeMap url=$url');
    bool canLaunchUrl = await canLaunch(url);

    if (!canLaunchUrl) {
      ToastUtil.show(msg: '未检测到高德地图~');
      return false;
    }

    await launch(url);

    return true;
  }
  /// 腾讯地图
  static Future gotoTencentMap(longitude, latitude,
      {String toAddress}) async {
    List list = GpsUtil.bd09_To_Gcj02(latitude, longitude);
    var url =
        'qqmap://map/routeplan?type=drive&fromcoord=CurrentLocation&tocoord=${list[0]},${list[1]}&referer=FN4BZ-6E33P-LFTDB-VRZ4C-NTP3Z-RVFFK&debug=true&to=${toAddress ?? ''}';
    print('gotoTencentMap url=$url');
    bool canLaunchUrl = await canLaunch(url);

    if (!canLaunchUrl) {
      ToastUtil.show(msg: '未检测到腾讯地图~');
      return false;
    }

    await launch(url);

    return canLaunchUrl;
  }

 
 /// 百度地图
  static Future gotoBaiduMap(longitude, latitude,
      {String toAddress}) async {
    var url =
        'baidumap://map/direction?destination=name:${toAddress ?? ''}|latlng:$latitude,$longitude&coord_type=bd09ll&mode=driving';
    url = Uri.encodeFull(url);
    print('gotoBaiduMap url=$url');

    bool canLaunchUrl = await canLaunch(url);

    if (!canLaunchUrl) {
      ToastUtil.show(msg: '未检测到百度地图~');
      return false;
    }

    await launch(url);

    return canLaunchUrl;
  }
  /// 苹果地图
  static Future gotoAppleMap(longitude, latitude,
      {String toAddress}) async {
    List list = GpsUtil.bd09_To_Gcj02(latitude, longitude);
    var url = 'http://maps.apple.com/?daddr=${list[0]},${list[1]}&address=$toAddress';
    url=Uri.encodeFull(url);
    print('url=$url');
    bool canLaunchUrl = await canLaunch(url);

    if (!canLaunchUrl) {
      ToastUtil.show(msg: '打开失败~');
      return false;
    }

    await launch(url);
  }

你可能感兴趣的:(Flutter,flutter)