[英]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 之外的所有浏览器。
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.