简体   繁体   English

Flutter Web--位置权限在 Safari(Mac 和 iOS)上不起作用

[英]Flutter Web--Location permission does not work on Safari(Mac & iOS)

I am trying to request location in my app.我正在尝试在我的应用程序中请求位置。 It works in iOS, Android, and every browser except Safari on Mac and iOS.它适用于 iOS、Android,以及除 Mac 上的 Safari 和 iOS 之外的所有浏览器。

EDIT编辑

Since none of the plugins worked for Safari, I decided to go with native dart2js solution.由于没有插件适用于 Safari,我决定使用原生 dart2js 解决方案 go。

@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,
        });

The solution is copied wholesale from here .该解决方案是从此处批发复制的。 The demo for this post works fine with on Safari. What am I doing wrong?这篇文章的演示在 Safari 上运行良好。我做错了什么?

There's a reputable package geolocator by Baseflow , see that it has the Flutter favorite badget . Baseflow 有一个著名的 package geolocator器,看到它有Flutter 最喜欢的徽章。

You can check the web docs and the example they provide, and maybe this fits with your problem.您可以查看web 文档及其提供的示例,也许这适合您的问题。

Good luck !祝你好运 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 flutter web forms 在 mac 浏览器(firefox、chrome)中工作,但在 windows 或 ios 浏览器(firefox、chrome、safari)中不起作用 - flutter web forms work in mac browsers (firefox, chrome) but not in windows or ios browsers (firefox, chrome, safari) 在iOS上使用Flutter授予位置权限 - Granting location permission with Flutter at iOS Flutter:在权限处理程序中添加对IOS的定位权限 - Flutter: Add location permission on IOS in permission handler 重新询问 flutter web 的位置许可 - Re ask location permission for flutter web Flutter permission_handler IOS 位置 - Flutter permission_handler IOS location Flutter iOS 请求位置权限不提示任何内容 - Flutter iOS request location permission not prompting anything Flutter permission_handler:请求iOS的位置权限 - Flutter permission_handler : request location permission on iOS iOS (Safari) 中的 Flutter web 状态栏 - Flutter web status bar in iOS (Safari) Flutter(在 iOS 上)- 在运行时请求位置权限,没有出现对话框! (定位包) - Flutter (on iOS) - Asking for location permission on runtime, no dialog appearing! (Location package) 在 iOS 环境(野生动物园)的颤振 Web 中未打开新选项卡 - New tab not opening in flutter web on iOS environment (safari)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM