问题
I have implemented Google map in my app. When i click on the current location button i wanted to show alert box if Gps is not enabled.
I tried this way where i got the view of that button.
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
View plusMinusButton = fm.getView().findViewById(1);
View locationButton = fm.getView().findViewById(2);
Using that locationButton
i tried to use setOnclickListener
but that did not help.
My requirement is simple when i click on this image

回答1:
This was a request and Google added it as a feature (in August 2013 I think). Now you can listen to clicks on the location button like this:
final Context context = this;
mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
@Override
public boolean onMyLocationButtonClick() {
LocationManager mgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!mgr.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Toast.makeText(context, "GPS is disabled!", Toast.LENGTH_SHORT).show();
}
return false;
}
});
来源:https://stackoverflow.com/questions/25361367/android-google-map-on-click-of-current-location-button-show-alert-box-if-gps-not