我一直在一个团队中工作,使用 Flutter 开发应用程序。我们需要使用 GPS 跟踪行驶的距离,但挑战在于Flutter 不再允许前景和后台位置跟踪(即使具有粗略的准确度)。
\n根据对最新 Google 指南的审查,Google 似乎应该允许我们的应用程序在后台\xe2\x80\x99s 时跟踪设备,但事实并非如此。事实上,打开前台和后台定位服务似乎在一两个月前就起作用了。我们已经尝试过location和geolocation软件包,但没有成功。当应用程序位于后台时,它们中的任何一个都会立即停止跟踪,并且当应用程序返回前台时,我们的位置会发生很大的跳跃。
...\n<uses-permission android:name="android.permission.ACCESS_COURSE_LOCATION"/>\n<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>\n...\n\nRun Code Online (Sandbox Code Playgroud)\n...\nserviceEnabled = await Geolocator.isLocationServiceEnabled();\nif (!serviceEnabled) {\n return Future.error('Location services are disabled.');\n}\n\npermission = await Geolocator.checkPermission();\nif (permission == LocationPermission.denied) {\n permission = await Geolocator.requestPermission();\n if (permission == LocationPermission.denied) {\n return Future.error('Location permissions are denied');\n }\n}\n\n//Permission returns denied Location \n//this is due to the background permission in the android manifest\n//turn off background permission and …Run Code Online (Sandbox Code Playgroud)