我使用最新版本的Google Play服务(7.0)并按照其指南中给出的步骤操作,并启用了如下所示的位置对话框,其中包含"从不"按钮.我的应用程序强制要求位置,所以我不想向用户显示永远不会,因为一旦用户点击"从不",我就无法再获取位置或请求位置.
谷歌地图只有是和没有按钮没有从不按钮,任何想法如何实现相同?
我的应用程序的图像

谷歌地图的形象

我的应用程序的一部分需要位置服务,因此如果当前关闭位置,应用程序将提示用户启用它.下面是我正在做它:(也见于这个堆栈溢出的答案)
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>()
{
@Override
public void onResult(LocationSettingsResult result)
{
final Status status = result.getStatus();
final LocationSettingsStates = result.getLocationSettingsStates();
switch (status.getStatusCode())
{
case LocationSettingsStatusCodes.SUCCESS:
// All location settings are satisfied. The client can initialize location
// requests here.
...
Log.d("onResult", "SUCCESS");
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Location settings are not satisfied. But could be fixed by showing the user
// a dialog.
Log.d("onResult", "RESOLUTION_REQUIRED");
try …Run Code Online (Sandbox Code Playgroud) 如何通过点击弹出屏幕上的"开启"选项(无需导航到位置设置),以编程方式启用GPS,因为它确实发生在官方Google地图应用中?
是否可以以编程方式打开设备上的LocationProviders(GPS提供商/网络提供商),如果它已关闭?
我们正在迁移到 Flutter。我们使用此线程打开位置服务而无需导航到设置页面
如何在 Flutter 中实现这一点?
导航到设置的当前临时代码:
Future _getCurrentLocation() async {
Position position;
try {
position = await Geolocator().getCurrentPosition(
desiredAccuracy: LocationAccuracy.bestForNavigation);
} on PlatformException catch(e){
print(e.code);
if(e.code =='PERMISSION_DISABLED'){
print('Opening settings');
await openLocationSetting();
try {
position = await Geolocator().getCurrentPosition(
desiredAccuracy: LocationAccuracy.bestForNavigation);
} on PlatformException catch(e){
print(e.code);
}
}
}
setState(() {
// _center = LatLng(currentLocation['latitude'], currentLocation['longitude']);
_center = LatLng(position.latitude, position.longitude);
});
}
Future openLocationSetting() async {
final AndroidIntent intent = new AndroidIntent(
action: 'android.settings.LOCATION_SOURCE_SETTINGS',
);
await intent.launch();
}
Run Code Online (Sandbox Code Playgroud) 如果GPS被激活或停用,有没有办法找到Flutter?我使用插件位置但是我只获得位置而不是GPS的状态.
我搜索了很多有关以编程方式打开GPS的信息,但没有找到任何解决方案。但是有些像Waze这样的应用程序不是系统应用程序,可以打开GPS!
例如,在显示该窗口的Waze中(如果GPS关闭!):
然后单击“打开GPS”将显示以下内容:
GPS将会自动开启!我们怎样才能像位智一样做到这一点?