map_util.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import 'dart:io';
  2. import 'package:bbyyy/my_tools/my_tools.dart';
  3. import 'package:url_launcher/url_launcher.dart';
  4. class MapUtil {
  5. /// 高德地图
  6. static Future<bool> gotoAMap(longitude, latitude) async {
  7. var url =
  8. '${Platform.isAndroid ? 'android' : 'ios'}amap://navi?sourceApplication=bby&lat=$latitude&lon=$longitude&dev=0&style=2';
  9. bool canLaunchUrl = await canLaunch(url);
  10. if (!canLaunchUrl) {
  11. showToast('未检测到高德地图~');
  12. return false;
  13. }
  14. await launch(url);
  15. return true;
  16. }
  17. /// 腾讯地图
  18. static Future<bool> gotoTencentMap(longitude, latitude) async {
  19. var url =
  20. 'qqmap://map/routeplan?type=drive&fromcoord=CurrentLocation&tocoord=$latitude,$longitude&referer=IXHBZ-QIZE4-ZQ6UP-DJYEO-HC2K2-EZBXJ';
  21. bool canLaunchUrl = await canLaunch(url);
  22. if (!canLaunchUrl) {
  23. showToast('未检测到腾讯地图~');
  24. return false;
  25. }
  26. await launch(url);
  27. return canLaunchUrl;
  28. }
  29. /// 百度地图
  30. static Future<bool> gotoBaiduMap(longitude, latitude) async {
  31. var url =
  32. 'baidumap://map/direction?destination=$latitude,$longitude&coord_type=bd09ll&mode=driving';
  33. bool canLaunchUrl = await canLaunch(url);
  34. if (!canLaunchUrl) {
  35. showToast('未检测到百度地图~');
  36. return false;
  37. }
  38. await launch(url);
  39. return canLaunchUrl;
  40. }
  41. /// 苹果地图
  42. static Future<bool> gotoAppleMap(longitude, latitude) async {
  43. var url = 'http://maps.apple.com/?&daddr=$latitude,$longitude';
  44. bool canLaunchUrl = await canLaunch(url);
  45. if (!canLaunchUrl) {
  46. showToast('打开失败~');
  47. return false;
  48. }
  49. await launch(url);
  50. }
  51. }