【问题标题】:Custom InfoWindowAdapter is not calling from onMarkerClick()自定义 InfoWindowAdapter 未从 onMarkerClick() 调用
【发布时间】:2013-11-05 22:42:07
【问题描述】:

我将CustomInfoWindow 设置为在用户点击制造商时调用。我在创建 Map 时不调用它,但仅在用户单击 Marker 时调用它。

我有不同的覆盖,它们有不同的 infoWindows 实现 覆盖类构建infoWindow,如下所示。

public  void onTap(AndroidMapOverlayItem item) {

  String overlayType = "";

  googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

 /*
  * some code to find overlayType
  */

        @Override
        public View getInfoWindow(Marker marker) {

            return null;
        }

        @Override
        public View getInfoContents(Marker marker) {

            if ("mylocation".equalsIgnoreCase(overlayType)) {


                // set title
                ((TextView)infoWindow.findViewById(R.id.title)).setText("Title");

                // set distance
                ((TextView)infoWindow.findViewById(R.id.text)).setText(display);

            }
            return infoWindow;

        }
    });
 }

下面是我的活动类,它选择用户点击并找到哪个标记。根据标记,我称其为相关的覆盖类。该覆盖类具有要在信息窗口中显示的信息。 活动类。

googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
googleMap.setOnMarkerClickListener(this);        

@Override
public boolean onMarkerClick(final Marker marker) {
    Log.d(TAG,"Inside onMakerClick "+marker);


    /*
             * find the relevant overlay class and try to fire it's onTap event.
             * onTap event has what needs to be done with specific marker.
             * Different marker has different information to show.
             *
             */
    overlay.onTap(overlayItem);


    return true;

}

这是我想要的,因为当我在第一个实例中设置 CustomInfowindow 时,所有标记都显示相同的信息。

【问题讨论】:

    标签: android google-maps-markers google-maps-android-api-2


    【解决方案1】:

    我已经解决了。现在,当我单击每个标记时,我会看到不同的信息。

    我在onMarkerClick(final Marker marker) 中的overlay.onTap(overlayItem) 之后添加以下代码

        if (!marker.isInfoWindowShown())
            marker.showInfoWindow();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-02
      • 2013-12-04
      • 2014-03-15
      • 2020-10-05
      • 1970-01-01
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      相关资源
      最近更新 更多