我应该在mapbox中的InfoWindow方法中返回什么视图?

时间:2017-10-25 09:05:07

标签: java android mapbox mapbox-android

我想在用户点击标记时显示infoWindow。我应该在Infowindow内部返回什么,以便在点击标记时显示默认的信息窗口?非常感谢任何帮助。提前谢谢。

以下是代码:

    public class LocationFetcher {
    private MapView mapView;

    private List<DeliveryPersonModel> persons=new ArrayList<>();

    //Mock Deliveryboys location
    DeliveryPersonModel person1 =new DeliveryPersonModel("DiMaria",R.drawable.pic_dimaria,new LatLng(34.01885992,-118.2722854));
    DeliveryPersonModel person2=new DeliveryPersonModel("Sergio",R.drawable.pic_ramos,new LatLng(33.8537663,-117.9904174));
    DeliveryPersonModel person3=new DeliveryPersonModel("Robert",R.drawable.pic_firmino,new LatLng(33.5649706,-117.206611));

    IconFactory iconFactory;

    public void showLocations(final Context context){
        mapView= ManagerActivity.mapView;
        iconFactory=IconFactory.getInstance(context);

        persons.add(person1);
        persons.add(person2);
        persons.add(person3);

        mapView.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(final MapboxMap mapboxMap) {

                for(int i=0;i<persons.size();i++){
                    DeliveryPersonModel model=persons.get(i);
                    mapboxMap.addMarker(generateMarker(model.getName(),model.getLocation(),model.getImgPic()));
                }

                mapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() {
                    @Nullable
                    @Override
                    public View getInfoWindow(@NonNull Marker marker) {
                        //What should I do here?
                        return null;
                    }
                });

            }
        });
    }

    private MarkerOptions generateMarker(String name,LatLng pos,int image) {
        MarkerOptions marker=new MarkerOptions();
        marker.title(name);
        marker.position(pos);
        marker.icon(iconFactory.fromResource(image));

        return marker;
    }
}

1 个答案:

答案 0 :(得分:1)

尝试返回此

return v = getActivity().getLayoutInflater().inflate(R.layout.inflater_marker, null);