【问题标题】:open location coordinates in my flutter app在我的颤振应用中打开位置坐标
【发布时间】:2022-01-03 01:45:52
【问题描述】:

我想在我的颤振应用中打开谷歌地图位置链接并从链接中检索纬度和经度并对其执行一些操作,例如获取到该坐标的方向

例如当我点击链接时:https://www.google.com/maps?q=45.100083,96.2000699&z=17&hl=en

它在选项之间显示我的应用程序,如下所示:

注意:我寻找了一些解决方案,例如 uni_links 包,但我无法正确解决。

【问题讨论】:

    标签: android ios flutter location deep-linking


    【解决方案1】:

    首先,您需要在您的 pubspec.yaml 中添加包 url_launcher,以便在您的智能手机中使用 url_launcher 方法中的 LatLng 值直接链接打开地图

    void _launchShareLocUrl() async {
      final url =
          'http://maps.google.com/maps?q=${data.latitude},${data.longitude}';
      if (await canLaunch(url)) {
        await launch(url);
      } else {
        throw 'Could not launch $url';
      }
    }
    

    你可以像这个例子一样在onPressed:按钮中调用方法名

    TextButton(
          onPressed: () => _launchShareLocUrl(), child: Text("Maps")),
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-03
    • 2021-06-25
    • 1970-01-01
    • 2021-04-21
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    • 2019-09-27
    相关资源
    最近更新 更多