简体   繁体   中英

Android Gmaps prompt user to enable gps on MyLocationButton click

The problem: MyLocationButton is enabled on Google Maps and GPS is off. When the user clicks on it, it just fails silently. This is a quite bad user interaction. I would like it to prompt the user to change GPS settings (like it actually does on google maps).

It seems i can redefine the handler for the button, but i like the waiting for user location and centering map part (and would gladly avoid rewriting it). Is there any way to catch the button failure event?

Thanks.

i think this will be solve it by checking if GPS is enabled and alert the user if it is disabled. i copied the code from 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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM