alert location services disabled when click mylocation button

196 Views Asked by At

I've enabled My Location button with this code in my google map

googleMap.setMyLocationEnabled(true);

When I click on My Location button

If the location services is disabled, related messages ("location services disabled") are not shown for me

I want this message to be shown if it is disabled, such as Google Maps software.

1

There are 1 best solutions below

0
Simas On BEST ANSWER

Well you can implement that yourself quite easily:

googleMap.setOnMyLocationButtonClickListener(new GoogleMap
        .OnMyLocationButtonClickListener() {
    @Override
    public boolean onMyLocationButtonClick() {
        final LocationManager manager = (LocationManager)
                getSystemService(Context.LOCATION_SERVICE);

        if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER) ) {
            Toast.makeText(MainActivity.this, "GPS not available!",
                    Toast.LENGTH_SHORT).show();
            return true; // GPS not available, consume the click
        }
        return false;
    }
});