How to use OnMarkerClickListener

北战南征 提交于 2019-12-24 00:59:05

问题


I'm trying to make an application that allows to open new activity from a marker on the map with the method GoogleMap.OnMarkerClickListener but do not know how to use it. Does anyone help me?


回答1:


Just use this:

getMap().setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

        public void onInfoWindowClick(Marker marker) {
            Intent i = new Intent(getActivity(), NewActivity.class);
            startActivity(i);

        }
    });

I used this code in my custom class that extends MapFragment I've placed it in this method:

@Override
public void onActivityCreated(Bundle savedInstanceState) {

}



回答2:


When touching Info window within a marker, if changing the current screen into another screen(class or Activity), Do this below;

private GoogleMap mMap:

.....
protected void onCreate(Bundle savedInstanceState) {
.....

private void setUpMap() {
.....
mMap.setOnInfoWindowClickListener(this);

@Override
    public void onInfoWindowClick(Marker marker) {
        // When touch InfoWindow on the market, display another screen. 
        Intent intent = new Intent(this, Another.class);
        startActivity(intent);
    }


来源:https://stackoverflow.com/questions/13958669/how-to-use-onmarkerclicklistener

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