Reputation: 8177
I enabled the my-location layer of the Google Maps Android API v2, which adds the floating button to go to the user's current location. I need a way to detect a click on this button. Is this possible?
Upvotes: 20
Views: 34150
Reputation: 875
Since this question was posted, Google has updated the API. They have added an onMyLocationButtonClick()
listener.
To add the listener:
//add location button click listener
map.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener(){
@Override
public boolean onMyLocationButtonClick()
{
//TODO: Any custom actions
return false;
}
});
Returning false will essentially call the super method. Returning true will not.
Upvotes: 53
Reputation: 4789
The latest release of Google Maps android api V2 in August contains a listener method for clicks of my location button : onMyLocationButtonClick () This can be used to know when the user has clicked the button and returns true if the listener has consumed the event
Upvotes: 29
Reputation: 37
This is good to know as I was also wondering about this. Now, is there a way to know whether or not Google's location service is enabled so we can decide whether or not we want to enable the button or not? No sense having a button that doesn't do anything so the workaround (disabling that button always) seems to be the only option for now.
Upvotes: 0
Reputation: 4081
No, currently there is no way to get that information. There is a feature request raised for that and it is already Acknowledged by Google.
Star it if you want a quicker fix:
Workaround:
Disable the built-in control and create your own View and add it to the screen. Set an onClickListener to this button and animate the map to the map's location.
Disable the default control:
UiSettings.setMyLocationButtonEnabled(false)
Get my location from the map:
GoogleMap.getMyLocation()
Upvotes: 10