【问题标题】:Unable to get click event on custominfo window of marker on googlemap V2 in android无法在android中googlemap V2上标记的custominfo窗口上获取点击事件
【发布时间】:2014-07-25 06:21:30
【问题描述】:

我正在通过这个reference 在标记上显示自定义信息窗口。 现在我可以显示自定义 infoWindow 了

但问题是我无法在每个按钮上获得右键单击事件。 例如当我点击 button1 时,它会调用 button2 的 touchlistener 等等。 我的代码是:

this.button1Listener = new OnInfoWindowElemTouchListener(
            button1, getResources().getDrawable(
                    R.drawable.ic_plusone_medium_off_client),
            getResources().getDrawable(
                    R.drawable.ic_plusone_tall_off_client)) {
        @Override
        protected void onClickConfirmed(View v, Marker marker) {
            // Here we can perform some action triggered after clicking the
            // button

            Toast.makeText(MapActivity.this, "Button1", Toast.LENGTH_SHORT)
                    .show();

        }
    };

this.button2Listener = new OnInfoWindowElemTouchListener(
                button2, getResources().getDrawable(
                        R.drawable.ic_plusone_medium_off_client),
                getResources().getDrawable(
                        R.drawable.ic_plusone_tall_off_client)) {
            @Override
            protected void onClickConfirmed(View v, Marker marker) {
                // Here we can perform some action triggered after clicking the
                // button

            Toast.makeText(MapActivity.this, "Button2", Toast.LENGTH_SHORT)
                    .show();

        }
    };

this.button3Listener = new OnInfoWindowElemTouchListener(
                button3, getResources().getDrawable(
                        R.drawable.ic_plusone_medium_off_client),
                getResources().getDrawable(
                        R.drawable.ic_plusone_tall_off_client)) {
            @Override
            protected void onClickConfirmed(View v, Marker marker) {
                // Here we can perform some action triggered after clicking the
                // button

            Toast.makeText(MapActivity.this, "Button3", Toast.LENGTH_SHORT)
                    .show();

        }
    }; and so on.......




this.button1.setOnTouchListener(button1Listener);
        this.button2.setOnTouchListener(button2Listener);
        this.button3.setOnTouchListener(button3Listener);
        .......
        // googleMap.setInfoWindowAdapter(null);
        googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker marker) {

            return null;
        }

        // Defines the contents of the InfoWindow
        @Override
        public View getInfoContents(Marker marker) {

            button1Listener.setMarker(marker);
            button2Listener.setMarker(marker);
            button3Listener.setMarker(marker);
            ......

            // We must call this to set the current marker and infoWindow
            // references
            // to the MapWrapperLayout
            mapWrapperLayout.setMarkerWithInfoWindow(marker, infoWindow);
            return infoWindow;

        }

    });

请告诉我,我做错了什么? 有时代码可以完美运行,但大多数时候它不起作用。 提前致谢。

【问题讨论】:

    标签: android google-maps google-maps-markers infowindow


    【解决方案1】:

    Google map V2 中的InfoWindow 是一个Image,库将它们全部渲染为图像。阅读maps Android API v2 中“自定义信息窗口”中的“注释”。

    所以你添加的所有按钮都不起作用。

    如果你真的想这样做,你必须做一些代码。我找到了一个here

    【讨论】:

    • 我正在使用相同的代码,但不幸的是没有按照要求对我工作。
    【解决方案2】:

    最后,我解决了按钮点击事件不匹配的问题。 问题就在这里。

    // MapWrapperLayout initialization
        // 39 - default marker height
        // 20 - offset between the default InfoWindow bottom edge and it's content bottom edge 
        mapWrapperLayout.init(map, getPixelsFromDp(this, 39 + 20)); 
    

    所以我只是改变了:

     mapWrapperLayout.init(map, getPixelsFromDp(this, 39 + 20)); 
    

    mapWrapperLayout.init(map, getPixelsFromDp(this, 0)); 
    

    所以信息窗口底部边缘和它的内容之间不会有任何偏移。

    我希望这会对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-10-06
      • 2019-09-02
      • 1970-01-01
      • 2013-10-06
      • 2013-11-19
      • 1970-01-01
      • 2013-08-07
      • 2017-05-15
      • 2023-04-04
      相关资源
      最近更新 更多