我目前正在使用geolocator插件来访问用户的位置(纬度/经度),但似乎尚不适用于网络。我试图找到一些方法来检索用户在Web中的位置,但是我没有找到它。
有人已经尝试过/找到要做的事情了吗?
谢谢,
Lionel
由于颤振团队的不和谐,我得以获得一些指导(特别感谢David Iglesias)。
为了能够检索我必须使用的Web部件的位置https://pub.dev/packages/js公开JavaScript API,并将其与https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API组合。
所以这里看起来像:
1)首先创建一个文件(例如:locationJs.dart)以显示JS函数:
@JS('navigator.geolocation') // navigator.geolocation namespace
library jslocation; // library name can be whatever you want
import "package:js/js.dart";
@JS('getCurrentPosition') // Accessing method getCurrentPosition from Geolocation API
external void getPosition(dynamic success);
2)调用新创建的文件
import 'package:Shared/locationJs.dart';
_getCurrentLocation() async {
//Check if the platform is web or not
if (kIsWeb) {
getPosition((value) => {
print(value.coords.latitude),
print(value.coords.longitude)
});
} else {
//Use Geolocator for Ios and Android
}
你去!