Reputation: 599
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.
Upvotes: 0
Views: 322
Reputation: 831
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();
}
Upvotes: -1