问题而在一种应用中使用2-图碎片(Issue while using 2 map fragments

2019-08-17 13:24发布

我想在两个不同的片段活动使用两个不同的地图片段。 而作为每SupportMapFragment设计,我保持在清单文件中appilcation属性的元标记地图键。 但是我的地图视图不清除,它显示在第二个片段与老点相同的地图eventhough我打电话“的GetMap()。明确的()”。 请建议

这是工作的罚款,直到除非我不要在一个单独的活动中使用新MapFragment,如果我使用新Mapfragment,它走的是同一个地图视图,因此地图视图未结算。

代码:

MAP片段

公共类DisplayMapFragment扩展SupportMapFragment实现OnMarkerClickListener,OnInfoWindowClickListener {

View mMapViewContainer;
MapView mMapView;

private Utill utilClass = Utill.getInstance(false);
private View v;
private MapView mapView;
private GeoPoint p;
private MapController mc;
private String latstr = "";
private String lonstr = "";
private String name, address;
private double lat;
private double lng;

ArrayList<NearByItem> NearByList=new ArrayList<NearByItem>();
private LatLng mPosFija;
private ArrayList<Double> mlat, mlong;
private ViewGroup parent;
Utill utilclass=Utill.getInstance(false);
Bitmap bmp;
ImageView ivIcon;
StringBuilder sbc=new StringBuilder();

ProgressBar progressbar;
public ImageLoader imageLoader;     
public DisplayMapFragment() {
    super();

}

public static DisplayMapFragment newInstance(LatLng posicion) {
    DisplayMapFragment frag = new DisplayMapFragment();
    frag.mPosFija = posicion;
    return frag;

}

@Override
public void onCreate(Bundle arg0) {
    // TODO Auto-generated method stub
    super.onCreate(arg0);
    NearByList=NearByMapActivity.fltrdNearByLists;
    imageLoader=new ImageLoader(this.getActivity().getApplicationContext());

}

@Override
public View onCreateView(LayoutInflater arg0, ViewGroup arg1, Bundle arg2) {
    View v = super.onCreateView(arg0, arg1, arg2);
    mlat = new ArrayList<Double>();
    mlong = new ArrayList<Double>();
    parent=arg1;
    if(NearByMapActivity.fltrdNearByLists!=null && !NearByMapActivity.fltrdNearByLists.isEmpty())
            NearByList.addAll(NearByMapActivity.fltrdNearByLists);
    else
        NearByList.addAll(Utill.NearbyList);


    NearByMapActivity parentActivity = (NearByMapActivity) getActivity();

    return v;
}

public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
    private List<OverlayItem> items;
    private Drawable marker;

    public MyItemizedOverlay(Drawable defaultMarker) {
        super(defaultMarker);
        items = new ArrayList<OverlayItem>();
        marker = defaultMarker;
    }

    @Override
    protected OverlayItem createItem(int index) {
        return items.get(index);
    }

    @Override
    public int size() {
        return items.size();
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, shadow);
        boundCenterBottom(marker);
    }

    public void addItem(OverlayItem item) {
        items.add(item);
    }

    public void populateNow() {
        populate();
    }

    @Override
    protected boolean onTap(int index) {

        return true;
    }

}

private void initMap() {

    UiSettings settings = getMap().getUiSettings();
    settings.setAllGesturesEnabled(true);
    // settings.setMyLocationButtonEnabled(true);
    settings.isZoomControlsEnabled();
    getMap().setTrafficEnabled(true);
    getMap().getMaxZoomLevel();
    // getMap().setMyLocationEnabled(true);

    if(NearByMapActivity.fltrdNearByLists!=null && !NearByMapActivity.fltrdNearByLists.isEmpty())
    getMap().moveCamera(
            CameraUpdateFactory.newLatLngZoom(
                    new LatLng(Double.parseDouble(NearByMapActivity.fltrdNearByLists.get(0).getLocationLat()), 
                            Double.parseDouble(NearByMapActivity.fltrdNearByLists.get(0).getLocationLong())), 14));
    getMap().isTrafficEnabled();
    // getMap().addGroundOverlay(new GroundOverlayOptions().)

    getMap().setOnMarkerClickListener(this);
    getMap().setOnInfoWindowClickListener(this);

            marker=new MarkerOptions()
                        .position(
                                new LatLng(
                                        Double.parseDouble(item.getLocationLat()), 
                                        Double.parseDouble(item.getLocationLong())))
                        .title(""+item.getStoreTitle())
                        .icon(bitmapLoyalty
                                ).snippet(sbc.toString());
        else
            marker=new MarkerOptions()
        .position(
                new LatLng(
                        Double.parseDouble(item.getLocationLat()), 
                        Double.parseDouble(item.getLocationLong())))
        .title(""+item.getStoreTitle())
        .icon(bitmapIconNearBy
                ).snippet(sbc.toString());



Marker marker1=getMap().addMarker(marker);

PopupWindowAdapter view1=new PopupWindowAdapter();

this.getMap().setInfoWindowAdapter(view1);


        // .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

bmp=BitmapFactory.decodeResource(getResources(),R.drawable.orgr_icon);
    }
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);
    initMap();
     getMap().addMarker(new MarkerOptions().position(new
LatLng(36.865814,-119.758399)).icon(BitmapDescriptorFactory.fromResource(R.drawable.red_pin)));
     //getMap().addGroundOverlay(new GroundOverlay(null));

/ *的GetMap()addGroundOverlay(新的GroundOverlayOptions()图像配(图像).positionFromBounds(边界).transparency(0.5)); * /}

@Override
public void onPause() {
    super.onPause();

//getMap().clear();
}
public void onResume(){
    super.onResume();
    if(NearByMapActivity.mainMapView!=null)
        //if(NearByMapActivity.mainMapView.getVisibility()==View.GONE)
                NearByMapActivity.mainMapView.setVisibility(View.VISIBLE);
}

@Override
public boolean onMarkerClick(Marker arg0) {
    // TODO Auto-generated method stub
    Log.e("cleared", "");
    return false;
}

}

public void onStop(){
    super.onStop();
    //getMap().clear();
}

}

MAP活动:活动类开始片段。

public class NearByMapActivity extends FragmentActivity{

onCreate(){
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            Fragment frag=new DisplayMapFragment();
            transaction.add(R.id.middle_view, frag);
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
            transaction.addToBackStack(null);
            transaction.commit();
}
}

Answer 1:

你可能会受此漏洞: https://code.google.com/p/gmaps-api-issues/issues/detail?id=5027&thanks=5027&ts=1362071369



Answer 2:

非常感谢你!!!!!!!!!!!!!

我尝试这一点,就像一个魅力的工作:)

public void hideStupidMaps() {
        mMapView.getLayoutParams().height = 1;
        mMapView.getLayoutParams().width = 1;
        mMapView.invalidate();
        mMapView.requestLayout();

    }


文章来源: Issue while using 2 map fragments in One application