簡體   English   中英

Android Gmaps提示用戶在MyLocationButton單擊上啟用gps

[英]Android Gmaps prompt user to enable gps on MyLocationButton click

問題:在Google地圖上啟用了MyLocationButton,而GPS已關閉。 當用戶單擊它時,它只是默默地失敗。 這是非常糟糕的用戶交互。 我希望它提示用戶更改GPS設置(就像在Google地圖上實際所做的一樣)。

看來我可以重新定義按鈕的處理程序,但是我喜歡等待用戶位置和居中地圖部分(很高興避免重寫它)。 有什么辦法可以捕獲按鈕失敗事件?

謝謝。

我認為這將通過檢查GPS是否啟用來解決,並警告用戶是否禁用它。 我從此鏈接復制了代碼。

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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM