【问题标题】:Flutter Web--Location permission does not work on Safari(Mac & iOS)Flutter Web--位置权限在 Safari(Mac & iOS) 上不起作用
【发布时间】:2021-09-22 06:52:48
【问题描述】:

我正在尝试在我的应用中请求位置。它适用于 iOS、Android 以及除 Mac 和 iOS 上的 Safari 之外的所有浏览器。

编辑

由于没有一个插件适用于 Safari,我决定使用原生 dart2js 解决方案。

@JS('navigator.geolocation')
library jslocation;

import 'package:js/js.dart';

@JS('getCurrentPostion')
external void getCurrentPostion(Function success(GeolocationPostion pos));

@JS()
@anonymous
class GeolocationPostion {
  external factory GeolocationPostion({GeolocationCoordinates coords});

  external GeolocationCoordinates get coords;
}

@JS()
@anonymous
class GeolocationCoordinates {
  external factory GeolocationCoordinates({
    double latitude,
    double longitude,
  });

  external double get latitude;
  external double get longitude;
}



double _latitude;
        double _longitude;

        getCurrentPostion((pos) => allowInterop((GeolocationPostion pos) {
              _latitude = pos.coords.latitude;
              _longitude = pos.coords.longitude;
            }));

        return LocationData.fromMap({
          'latitude': _latitude,
          'longitude': _longitude,
        });

该解决方案是从here 批发复制的。 demo for this 帖子在 Safari 上运行良好。我做错了什么?

【问题讨论】:

  • 我看到的唯一区别是演示在按下按钮时获取位置!你能试试这个吗?
  • 您是否收到任何可以从 Safari Mac 反馈的控制台错误?
  • @ErmiyaEskandary 也没有控制台错误。
  • 你找到解决办法了吗?
  • @PRATHIV 我在 Safari 中使用反向地理编码 API。我用的是mapbox,你可以用谷歌地图。

标签: flutter safari flutter-web


【解决方案1】:

有一个有信誉的包geolocator by Baseflow,看看它有Flutter favorite badget

您可以查看他们提供的web docsexample,也许这符合您的问题。

祝你好运?!

【讨论】:

  • 这是尝试过的原始解决方案
猜你喜欢
  • 2019-05-21
  • 1970-01-01
  • 1970-01-01
  • 2022-08-02
  • 2020-12-02
  • 1970-01-01
  • 2017-09-03
  • 2021-01-25
  • 2014-01-21
相关资源
最近更新 更多