openMapByAddress static method

Future<String?> openMapByAddress(
  1. BuildContext context,
  2. String address
)

IOS 需要在 info.plist 文件中添加白名单

Implementation

static Future<String?> openMapByAddress(BuildContext context, String address) async {
  var packageInfo = await DeviceUtil.packageInfo;
  String? urlGaode = await _canGaodde(packageInfo, address);
  String? urlBaidu = await _canBaidu(packageInfo, address);
  String? urlApple = await _canApple(packageInfo, address);
  /* if (urlGaode == null && urlBaidu == null && urlApple == null) {
    var url = "https://ditu.amap.com/search?query=$address";
    if (Platform.isIOS) {
      url = Uri.encodeFull(url);
    }
    await launch(url);
    return "h5";
  }*/
  List<Widget> list = <Widget>[];
  String? action = "";
  if (urlGaode != null) {
    list.add(CupertinoActionSheetAction(child: Text("高德地图"), onPressed: () async => action = await _toMap(context, urlGaode, "amap")));
  }
  if (urlBaidu != null) {
    list.add(CupertinoActionSheetAction(child: Text("百度地图"), onPressed: () async => action = await _toMap(context, urlBaidu, "baidu")));
  }
  if (urlApple != null) {
    list.add(CupertinoActionSheetAction(child: Text("苹果地图"), onPressed: () async => action = await _toMap(context, urlApple, "apple")));
  }

  var urlH5 = "https://ditu.amap.com/search?query=$address";
  if (Platform.isIOS) {
    urlH5 = Uri.encodeFull(urlH5);
  }
  list.add(CupertinoActionSheetAction(child: Text("网页版"), onPressed: () async => action = await _toMap(context, urlH5, "h5")));

  await showCupertinoModalPopup(
      context: context,
      builder: (c) =>
          CupertinoActionSheet(
            title: Text("选择地图", style: TextStyle(fontSize: 18)),
            cancelButton: CupertinoActionSheetAction(
                child: Text("取消", style: TextStyle(color: Colors.red)),
                onPressed: () {
                  action = "esc";
                  Navigator.pop(context);
                }),
            actions: list,
          ));
  return action;
}