Url_Launcher在iOS上打开任何Maps应用程序

时间:2019-09-12 20:28:21

标签: ios flutter

我正在Flutter中使用url_launcher软件包在Android和iOS上打开Goog​​le Maps或Apple Maps。到目前为止,它在Android设备上运行良好。但是,尝试在iOS上启动时遇到了问题。如果适用,我希望为用户提供选择(可能是从底部开始?)选择要使用的地图绘制应用程序的选择,但是目前,我只关心使其在iOS上起作用。

我的Info.plist文件中包含了必要的LSApplicationQueriesSchemes。我已经研究了来自Google和Apple的正确url方案,并且我相信它们是正确的(当然,尚待审核)。我曾就此问题咨询过其他SO职位,但没有发现运气。

namespace ScoreCalculator
{
    public partial class ScoreCalculator : Form
    {
        Int32 scoreTotal = 0;
        Int32 scoreCount = 0;
        public ScoreCalculator()
        {
            InitializeComponent();
        }
        private void AddBtn_Click(object sender, EventArgs e)
        {

            Int32 average;


            scoreCount +=1;
// the error vvvvvvv
            scoreTotal += Convert.ToInt32(scoreTotalTxt.Text);

            scoreTotalTxt.Text = Convert.ToString(scoreTotal);
            scoreCountTxt.Text = Convert.ToString(scoreCount);
            average = scoreTotal / scoreCount;
            averageTxt.Text = average.ToString();
            scoreTxt.Focus();
        }
}

并且如前所述-在我的Info.plist中:

Future<bool> launchMap(String addressLine1) async {
    String urlGoogleMaps =
        "https://www.google.com/maps/search/?api=1&query=$addressLine1";
    String urlAppleMaps = "https://maps.apple.com/?query=$addressLine1";
    if (await canLaunch(urlGoogleMaps)) {
      print('launching google url');
      await launch(urlGoogleMaps);
      return true;
    } else if (await canLaunch(urlAppleMaps)) {
      print('launching apple url');
      await launch(urlAppleMaps);
      return true;
    } else {
      throw 'Could not launch maps';
    }
  }

这是onTap部分:

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>googlechromes</string>
        <string>comgooglemaps</string>
        <string>waze</string>
    </array>

我希望用户单击地址1时打开Goog​​le Maps网址。如果没有Google Maps,请打开Apple Maps。目前,我收到“未处理的异常:无法启动地图”。

                        InkWell(
                          child: Text(
                            orderDetailModel.address().addressLine1,
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: screenAwareSize(15, 30, context),
                            ),
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                          ),
                          onTap: () => launchMap(orderDetailModel
                                  .address()
                                  .addressLine1 +
                              orderDetailModel.address().cityStatePostalCode()),
                        ),

编辑 我已经弄清楚了如何使用导入功能基于平台打开地图

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: Could not launch maps
#0      _OrderDetailsState.launchMap (package:etteo_mobile/widgets/order/order_detail.dart:359:7)
<asynchronous suspension>
#1      _OrderDetailsState.topPart.<anonymous closure> (package:etteo_mobile/widgets/order/order_detail.dart:303:40)
#2      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
#3      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:711:32)
#4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#5      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
#6      TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:312:7)
#7      GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
#8      _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
#9      _WidgetsFlutterBinding&<…>

并使用以下代码:

import 'dart:io' show Platform;

但是,现在我认为我遇到的问题是解析来自addressLine1输入的地址,并且收到以下消息。

  launchMap(String addressLine1) async {
    // Android
    var url = 'geo:52.32,4.917';
    if (Platform.isIOS) {
      // iOS
      url = 'http://maps.apple.com/?q=$addressLine1';
    }
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

其他人曾经经历过吗?我是否使用正确的Apple Maps查询参数(q =)?

谢谢

已修复

VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: Could not launch http://maps.apple.com/?q=123 Main StreetAlpharetta GA 30022
#0      _OrderDetailsState.launchMap (package:etteo_mobile/widgets/order/order_detail.dart:374:7)
<asynchronous suspension>
#1      _OrderDetailsState.topPart.<anonymous closure> (package:etteo_mobile/widgets/order/order_detail.dart:304:40)
#2      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
#3      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:711:32)
#4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#5      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
#6      TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:312:7)
#7      GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
#8      _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestur<…>

0 个答案:

没有答案