import 'dart:io'; import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; class XMapNavigatorUtil { /// 高德地图导航 static Future gotoAMap( {longitude, latitude, VoidCallback toInstallCallBack}) { var url = '${Platform.isAndroid ? 'android' : 'ios'}amap://navi?sourceApplication=amap&lat=$latitude&lon=$longitude&dev=0&style=2'; return gotoMap( url: url, toInstallCallBack: () { if (null != toInstallCallBack) { toInstallCallBack(); } }); } /// 腾讯地图导航 static Future gotoTencentMap( {longitude, latitude, VoidCallback toInstallCallBack}) async { var url = 'qqmap://map/routeplan?type=drive&fromcoord=CurrentLocation&tocoord=$latitude,$longitude&referer=IXHBZ-QIZE4-ZQ6UP-DJYEO-HC2K2-EZBXJ'; return gotoMap( url: url, toInstallCallBack: () { if (null != toInstallCallBack) { toInstallCallBack(); } }); } /// 百度地图导航 static Future gotoBaiduMap( {longitude, latitude, VoidCallback toInstallCallBack}) async { var url = 'baidumap://map/direction?destination=$latitude,$longitude&coord_type=gcj02&mode=driving'; return gotoMap( url: url, toInstallCallBack: () { if (null != toInstallCallBack) { toInstallCallBack(); } }); } /// 跳转到第三方地图 /// [url]跳转地址 /// [toInstallCallBack]地图未安装回调 static Future gotoMap( {String url, VoidCallback toInstallCallBack}) async { bool canLaunchUrl = await isMapInstall(url); if (!canLaunchUrl) { if (null != toInstallCallBack) { toInstallCallBack(); } return false; } await launch(url); return true; } static void toInstallMap(String url) { launch(url); } static Future isBaiduMapInstall() { return canLaunch('baidumap://map/direction'); } static Future isTencentMapInstall() { return canLaunch('qqmap://map/routeplan'); } static Future isAmapMapInstall() { return canLaunch('${Platform.isAndroid ? 'android' : 'ios'}amap://navi'); } /// 判断地图是否有安装 static Future isMapInstall(String url) { return canLaunch(url); } }