MapQuest(Android SDK):在地图上放置一个图钉并自动打开一个窗口

时间:2016-10-11 15:18:14

标签: android maps mapbox infowindow mapquest

我在我的应用程序中使用MapQuest Android SDK。 我有一个场景,我在地图上放置一个引脚,我想自动打开一个引脚窗口。

我正在使用 MapboxMap.InfoWindowAdapter 和方法 getInfoWindow(标记标记)。我的问题是如何在放下引脚时自动打开窗口。

enter image description here

我想在放下引脚后自动打开窗口吗?

这是我的代码:

     @Override
        public void onResume() {
            super.onResume();
    //This is where I pass my poi from poiSearchListview Fragment to my Map Fragment through Activity. So On onResume() if will call this method.
            if (null != getActivity.getPoiFields()) {
                fromSearchFrag = true;
                addPoiMarker(getActivity.getPoiFields());
         }
        }

这是我的OnCreateView()方法:

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.map, container, false);

 mMapView.getMapAsync(new OnMapReadyCallback() {

mPoiFields.clear();
if (null != getActivity.getPoiFields()) {
                    fromSearch = true;
                    addPoiMarker(getActivity.getPoiFields());
}

 mMapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() {
       @Nullable
                    @Override
                    public View getInfoWindow(@NonNull Marker marker) {

                        View customView = null;
**//Here I have my own window my own images, texts and buttons.**

                        return custom view;
                      }
            });
    }

});

这是我在OnResume()

上添加POIMarker的方法
        public void addPoiMarker(Fields poiFields) {
            final String name = poiFields.getName();
            poiAddress = poiFields.getAddress() + ", " + poiFields.getCity() + ", " + poiFields.getState();

            Drawable iconDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.pointofinterest);
            Icon icon = IconFactory.getInstance(getActivity()).fromDrawable(iconDrawable);
            if (mMapboxMap != null) {

                mMapboxMap.removeAnnotations(); // TO remove all the markers before dropping the Address marker from search.

                markerOptions = new MarkerOptions().icon(icon).position(
                        new LatLng(poiFields.getLat(), poiFields.getLng())).title(name);

                mSearchResultMarker = mMapboxMap.addMarker(markerOptions);
                mPoiFields.put(mSearchResultMarker, poiFields);



             //  mMapboxMap.selectMarker(mSearchResultMarker);
        // **IF I use selectMarker it shows just the address on the window and
 not my custom window. 
I want to show my custom info window here as selectMarker doesn't clear my issue, what to do ?**.
                }
                zoomToPin(poiFields.getLat(), poiFields.getLng());
            }

2 个答案:

答案 0 :(得分:2)

尝试使用mapboxMap.selectMarker()传递您要选择的标记。

编辑:我修改了演示应用示例CustomInfoWindowActivity,以生成您在下面评论中提到的两种情况。我通过简单地单击地图来模拟方案1(不是标记丢弃的动画),这会调用mapboxMap.selectMarker()并按预期显示自定义信息窗口。单击标记图标时,场景2也按预期工作。

enter image description here

如果我仍然不了解这个问题,请提供问题的其他代码和图片/视频/ GIF。

答案 1 :(得分:1)

您是否尝试在Marker上调用showInfoWindow()方法?