如何在Android的编程触发自定义信息窗口自定义、窗口、如何在、信息

2023-09-07 11:07:19 作者:┆猫着看戏︽⊙_⊙︽

我用自定义窗口的信息,但是,调用marker.showInfoWindow();始终呈现默认的窗口信息,而如果用户点击该标记,自定义窗口的信息都没有问题呈现。我可以编程方式打开我的自定义窗口的信息?

我的情况是,当标记绘制在地图上,一个特定的标志物应当显示其窗口信息(因此没有用户交互),但preferably一个自定义,如在我的CustomWindowInfoAdapter类中定义

编辑,很乐意删除这个问题,只是我是笨拙的,但也许有更多的人喜欢我在那里。不管怎么说,我的问题是,我在呼唤的 showInfoWindow 的添加适配器在我的方法之前的 resourceRe presentationsNearBy()的,所以很明显只有默认的信息窗口是以往任何时候都可能。所以我erroneus code:

 私人无效setUpMap(){
    ...

    //添加搜索结果标记到地图中。
    resourceRe presentationsNearBy();

    //设置自定义信息窗口
    mMap.setInfoWindowAdapter(新CustomInfoWindowAdapter());

            ...
   }
 

在这里的,纠正code是:

 私人无效setUpMap(){
    ...

    //设置自定义信息窗口
    mMap.setInfoWindowAdapter(新CustomInfoWindowAdapter());

    //添加搜索结果标记到地图中。
    resourceRe presentationsNearBy();

            ...
   }
 

解决方案

试试这个:

 私有静态GoogleMap的_googleMap = NULL;
...


公共静态无效initialize_google_map()
{
    _googleMap =((MapFragment)Context.getFragmentManager()findFragmentById(R.id.map)。)的GetMap()。

    ...

    _googleMap.setInfoWindowAdapter(新GoogleMap.InfoWindowAdapter(){
        @覆盖
        公共查看getInfoWindow(标记标记){
            返回build_info_window(标记);
        }
        @覆盖
        公共查看getInfoContents(标记为arg0){返回NULL;}
    });


}


私有静态视图build_info_window(标记标记)
{
    LayoutInflater充气=(LayoutInflater)Context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    查看custom_info_window = inflater.inflate(R.layout.custom_info_window,NULL);

    TextView的tv_title =(TextView中)custom_info_window.findViewById(R.id.tv_title);
    tv_title.setText(标题);

    等...等...
}
 
Android安卓编程入门 新建一个安卓程序

}

希望它帮助。

I use custom window info, however, calling marker.showInfoWindow(); always renders default window info, whilst if the user clicks on the marker, custom window info are rendered without problem. Can I programatically open my custom window info?

My case is that when the markers are drawn on the map, one particular marker should show its window info (so no user interaction), but preferably a custom one, as defined in my CustomWindowInfoAdapter class.

EDIT, would gladly delete this question, it was just me being clumsy, but maybe there's more guys like me out there. Anyways, my problem was that I was calling showInfoWindow before adding the adapter in my method resourceRepresentationsNearBy(), so obviously only the default info window was ever possible. So my erroneus code:

    private void setUpMap() {
    ...

    // Add search result markers to the map.
    resourceRepresentationsNearBy();

    // Setting up custom info window
    mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());

            ...
   }

where as, corrected code is:

    private void setUpMap() {
    ...

    // Setting up custom info window
    mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());

    // Add search result markers to the map.
    resourceRepresentationsNearBy();

            ...
   }

解决方案

Try this:

private static GoogleMap _googleMap = null;
...


public static void initialize_google_map()
{
    _googleMap = ((MapFragment)Context.getFragmentManager().findFragmentById(R.id.map)).getMap(); 

    ...

    _googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
        @Override
        public View getInfoWindow(Marker marker) {
            return build_info_window(marker);
        }
        @Override
        public View getInfoContents(Marker arg0) {return null;}
    });


}


private static View build_info_window(Marker marker)
{
    LayoutInflater inflater = (LayoutInflater)Context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View custom_info_window = inflater.inflate(R.layout.custom_info_window, null);

    TextView tv_title = (TextView)custom_info_window.findViewById(R.id.tv_title);
    tv_title.setText("Title");

    etc... etc...    
}

}

Hope it helps.