问题虽然在一个应用程序中使用2片图 [英] Issue while using 2 map fragments in One application

查看:163
本文介绍了问题虽然在一个应用程序中使用2片图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

code:

MAP片段

公共类DisplayMapFragment扩展SupportMapFragment工具
        OnMarkerClickListener,OnInfoWindowClickListener {

 查看mMapViewContainer;
图形页面mMapView;私人Utill utilClass = Utill.getInstance(假);
私人视图V;
私人MapView类MapView类;
私人的GeoPoint磷;
私人MapController MC;
私人字符串latstr =;
私人字符串lonstr =;
私人字符串名称,地址;
私人双重纬度;
私人双重液化天然气;ArrayList的< NearByItem> NearByList =新的ArrayList< NearByItem>();
私人经纬度mPosFija;
私人的ArrayList<双>多点定位,mlong;
私人的ViewGroup父;
Utill utilclass = Utill.getInstance(假);
BMP位图;
ImageView的ivIcon;
StringBuilder的SBC =新的StringBuilder();进度进度;
公共ImageLoader的ImageLoader的;
公共DisplayMapFragment(){
    超();}公共静态的newInstance DisplayMapFragment(职位的LatLng){
    DisplayMapFragment FRAG =新DisplayMapFragment();
    frag.mPosFija =职位;
    返回FRAG;}@覆盖
公共无效的onCreate(捆绑为arg0){
    // TODO自动生成方法存根
    super.onCreate(为arg0);
    NearByList = NearByMapActivity.fltrdNearByLists;
    ImageLoader的=新ImageLoader的(this.getActivity()getApplicationContext());}@覆盖
公共查看onCreateView(LayoutInflater为arg0,ARG1的ViewGroup,捆绑ARG2){
    视图V = super.onCreateView(为arg0,ARG1,ARG2);
    MLAT =新的ArrayList<双>();
    mlong =新的ArrayList<双>();
    父= ARG1;
    如果(NearByMapActivity.fltrdNearByLists = NULL&放大器;!&安培;!NearByMapActivity.fltrdNearByLists.isEmpty())
            NearByList.addAll(NearByMapActivity.fltrdNearByLists);
    其他
        NearByList.addAll(Utill.NearbyList);
    NearByMapActivity parentActivity =(NearByMapActivity)getActivity();    返回伏;
}公共类MyItemizedOverlay扩展ItemizedOverlay< OverlayItem> {
    私人列表< OverlayItem>项目;
    私人绘制对象标记;    公共MyItemizedOverlay(可绘制defaultMarker){
        超(defaultMarker);
        项目=新的ArrayList< OverlayItem>();
        标记= defaultMarker;
    }    @覆盖
    保护OverlayItem createItem中(INT指数){
        返回items.get(索引);
    }    @覆盖
    公众诠释大小(){
        返回items.size();
    }    @覆盖
    公共无效画(油画画布,MapView类MapView类,布尔阴影){
        super.draw(画布,MapView类,阴影);
        boundCenterBottom(标记);
    }    公共无效的addItem(OverlayItem项){
        items.add(项目);
    }    公共无效populateNow(){
        填充();
    }    @覆盖
    保护布尔中的onTap(INT指数){        返回true;
    }}私人无效initMap(){    UiSettings设置=的GetMap()getUiSettings()。
    settings.setAllGesturesEnabled(真);
    // settings.setMyLocationButtonEnabled(真);
    settings.isZoomControlsEnabled();
    的GetMap()setTrafficEnabled(真)。
    。的GetMap()getMaxZoomLevel();
    //的GetMap()setMyLocationEnabled(真)。    如果(NearByMapActivity.fltrdNearByLists = NULL&放大器;!&安培;!NearByMapActivity.fltrdNearByLists.isEmpty())
    的GetMap()。moveCamera(
            CameraUpdateFactory.newLatLngZoom(
                    新经纬度(Double.parseDouble(NearByMapActivity.fltrdNearByLists.get(0).getLocationLat()),
                            Double.parseDouble(NearByMapActivity.fltrdNearByLists.get(0).getLocationLong())),14));
    的GetMap()isTrafficEnabled()。
    //的GetMap()。addGroundOverlay(新的GroundOverlayOptions()。)    的GetMap()setOnMarkerClickListener(本)。
    的GetMap()setOnInfoWindowClickListener(本)。            标记=新的MarkerOptions()
                        。位置(
                                新的经纬度(
                                        Double.parseDouble(item.getLocationLat()),
                                        Double.parseDouble(item.getLocationLong())))
                        .title伪(+ item.getStoreTitle())
                        .icon(bitmapLoyalty
                                )是.snippet(sbc.toString());
        其他
            标记=新的MarkerOptions()
        。位置(
                新的经纬度(
                        Double.parseDouble(item.getLocationLat()),
                        Double.parseDouble(item.getLocationLong())))
        .title伪(+ item.getStoreTitle())
        .icon(bitmapIconNearBy
                )是.snippet(sbc.toString());标记MARKER1 =的GetMap()addMarker(标记)。PopupWindowAdapter厂景=新PopupWindowAdapter();this.getMap()setInfoWindowAdapter(厂景)。
        // .icon(BitmapDesc​​riptorFactory.defaultMarker(BitmapDesc​​riptorFactory.HUE_RED)));BMP = BitmapFactory.de codeResource(getResources(),R.drawable.orgr_icon);
    }
}@覆盖
公共无效onActivityCreated(捆绑savedInstanceState){
    // TODO自动生成方法存根
    super.onActivityCreated(savedInstanceState);
    initMap();
     的GetMap()。addMarker(新的MarkerOptions()位置(新
。经纬度(36.865814,-119.758399))图标(BitmapDesc​​riptorFactory.fromResource(R.drawable.red_pin)));
     //getMap().addGroundOverlay(new地面叠加层(NULL));

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

  @覆盖
公共无效的onPause(){
    super.onPause();//的GetMap()清()。
}
公共无效onResume(){
    super.onResume();
    如果(NearByMapActivity.mainMapView!= NULL)
        //if(NearByMapActivity.mainMapView.getVisibility()==View.GONE)
                NearByMapActivity.mainMapView.setVisibility(View.VISIBLE);
}@覆盖
公共布尔onMarkerClick(标记为arg0){
    // TODO自动生成方法存根
    Log.e(清除,);
    返回false;
}}公共无效的onStop(){
    super.onStop();
    //的GetMap()清()。
}

}

MAP活动:Activity类开始片段

 公共类NearByMapActivity扩展FragmentActivity {的onCreate(){
            FragmentTransaction交易= getSupportFragmentManager()调用BeginTransaction()。
            片段FRAG =新DisplayMapFragment();
            transaction.add(R.id.middle_view,FRAG);
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
            transaction.addToBackStack(NULL);
            器transaction.commit();
}
}


解决方案

感谢ü这么多!!!!!!!!!!!!!

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

 公共无效hideStupidMaps(){
        。mMapView.getLayoutParams()高度= 1;
        。mMapView.getLayoutParams()宽度= 1;
        mMapView.invalidate();
        mMapView.requestLayout();    }

I am trying to use two different Map Fragment in two different Fragment Activities. And as per the SupportMapFragment design, I am keeping the map key in the META TAG of the appilcation properties in Manifest file. However my Map view is not clearing, it is showing same map with old points in the second Fragment eventhough I am calling "getMap().clear()". Please suggest

This is working fine untill and unless I dont use new MapFragment in a separate Activity, If I use new Mapfragment, it is taking the same map view, so the map view is not clearing.

Code :

MAP FRAGMENT

public class DisplayMapFragment extends SupportMapFragment implements 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(new GroundOverlayOptions() .image(image) .positionFromBounds(bounds) .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 ACTIVITY : Activity class to start Fragment.

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();
}
}

解决方案

Thank u so much!!!!!!!!!!!!!

I try this, and its work like a charm :)

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

    }

这篇关于问题虽然在一个应用程序中使用2片图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆