12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import 'dart:io';
- import 'package:flutter/material.dart';
- import 'package:url_launcher/url_launcher.dart';
- class XMapNavigatorUtil {
- /// 高德地图导航
- static Future<bool> 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<bool> 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<bool> 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<bool> 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<bool> isBaiduMapInstall() {
- return canLaunch('baidumap://map/direction');
- }
- static Future<bool> isTencentMapInstall() {
- return canLaunch('qqmap://map/routeplan');
- }
- static Future<bool> isAmapMapInstall() {
- return canLaunch('${Platform.isAndroid ? 'android' : 'ios'}amap://navi');
- }
- /// 判断地图是否有安装
- static Future<bool> isMapInstall(String url) {
- return canLaunch(url);
- }
- }
|