My location button event listener

て烟熏妆下的殇ゞ 提交于 2019-11-27 03:10:07

问题


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?


回答1:


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:

http://code.google.com/p/gmaps-api-issues/issues/detail?id=4789&q=apitype%3DAndroid2&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Stars%20ApiType%20Internal


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()



回答2:


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.




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/14777951/my-location-button-event-listener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!