【问题标题】:Android Gmaps prompt user to enable gps on MyLocationButton clickAndroid Gmaps 提示用户在 MyLocationButton 点击​​时启用 gps
【发布时间】:2017-02-05 22:25:33
【问题描述】:

问题:在 Google 地图上启用了 MyLocationButton,而 GPS 已关闭。当用户点击它时,它只是默默地失败。这是一个非常糟糕的用户交互。我希望它提示用户更改 GPS 设置(就像它在谷歌地图上所做的那样)。

似乎我可以重新定义按钮的处理程序,但我喜欢等待用户位置和居中地图部分(并且很乐意避免重写它)。有什么方法可以捕捉到按钮失败事件吗?

谢谢。

【问题讨论】:

  • @NicolasMaltais 谢谢。然而,这不是问题的重点。我知道如何提示用户输入 GPS。我想要的是捕捉 MyLocationButton 发送该请求的失败。
  • this method工作之后检查gps是否启用?

标签: android google-maps gps mylocationoverlay


【解决方案1】:

我认为这将通过检查 GPS 是否启用并在禁用时提醒用户来解决。我从this link复制了代码。

final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );

    if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
        buildAlertMessageNoGps();
    }

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Your GPS seems to be disabled, do you want to enable it?")
           .setCancelable(false)
           .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
               public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                   startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
               }
           })
           .setNegativeButton("No", new DialogInterface.OnClickListener() {
               public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                    dialog.cancel();
               }
           });
    final AlertDialog alert = builder.create();
    alert.show();
}

【讨论】:

  • 谢谢,但我的问题不是如何检查 GPS 是否处于活动状态,而是如何响应 MyLocationButton 故障。据我所知,这段代码并没有这样做,它只是在活动生命周期中调用它后检查 GPS 可用性。如果我错了,请纠正我
  • MyLocationButton 何时失败?当 GPS 被禁用时。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-27
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多