Android谷歌地图v2在标签重叠问题,多个地图在标签

Android谷歌地图v2在标签重叠问题,多个地图在标签,android,google-maps-android-api-2,android-maps,android-maps-v2,Android,Google Maps Android Api 2,Android Maps,Android Maps V2,我是android新手,现在正在使用Google maps v2,我使用tabhost显示Google map v2,在这个tabhost中,我需要在不同的选项卡上显示两个Google maps v2。当我切换选项卡b/w两个包含map的选项卡时,它会重叠。我不知道如何克服这个问题 //这两个选项卡的代码都在这里 mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))

我是android新手,现在正在使用Google maps v2,我使用tabhost显示Google map v2,在这个tabhost中,我需要在不同的选项卡上显示两个Google maps v2。当我切换选项卡b/w两个包含map的选项卡时,它会重叠。我不知道如何克服这个问题

//这两个选项卡的代码都在这里

    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
            .getMap();
    mMap.setMyLocationEnabled(true);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    //locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE, this);
    Log.e("locamanager",""+locationManager);
    Criteria criteria=new Criteria(); // object to retrieve provider
    String provider = locationManager.getBestProvider(criteria, true);
    Location location=locationManager.getLastKnownLocation(provider);
    if(location!=null){
        onLocationChanged(location);
    }
    locationManager.requestLocationUpdates(provider, 400, 1000, this);


 }


@Override
public void onLocationChanged(Location location) {

    latLng = new LatLng(location.getLatitude(), location.getLongitude());
    Log.e("latlng",""+latLng);
    cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 15);
    mMap.animateCamera(cameraUpdate);
    locationManager.removeUpdates(this);

    new ReverseGeocodingTask(getBaseContext()).execute(latLng);

}
谁有办法,请帮帮我


感谢您的帮助

我也遇到过同样的问题,但最终还是以这种方式解决了

首先,我创建了单独的MyMapFragment类,它扩展了android.support.v4.app.Fragment

下面是onCreateView方法

if (view != null) {

            ViewGroup parent = (ViewGroup) view.getParent();
            if (parent != null)
                parent.removeView(view);
        }

        try {
            view = (ViewGroup) inflater.inflate(R.layout.map_frag, container,
                    false);
            setUpMapIfNeeded();
            showMap(maptype);
        } catch (Exception e) {
        }
        return view;
之后,我创建了一个xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_fragmentView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
</LinearLayout>
在我这边很好,希望对你有帮助

地图片段代码在这里

public class MapFragment extends Fragment {

    private View view;
    private GoogleMap mMapView;

    public TouchableWrapper mTouchView;
    LinearLayout map_fragg;

    String userLat, userLon;

    int maptype = 1;

    Marker lastMarker = null;

    public MapFragment() {
    }

    public MapFragment(int maptype) {
        this.maptype = maptype;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        getView();
    }

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

        if (container == null) {
            return null;
        }

        if (view != null) {

            ViewGroup parent = (ViewGroup) view.getParent();
            if (parent != null)
                parent.removeView(view);

            if (mTouchView != null) {
                mTouchView.removeAllViews();
            }

        }

        try {
            mTouchView = new TouchableWrapper(getActivity());
            view = (ViewGroup) inflater.inflate(R.layout.map_frag, null, false);
            view.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));

            map_fragg = (LinearLayout) view.findViewById(R.id.map_fragg);
            mTouchView.addView(view);
            setUpMapIfNeeded();

        } catch (Exception e) {
            e.printStackTrace();
        }

        return mTouchView;

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    private void showMap(int maptype) {

        switch (maptype) {
        case 1:
            setMapX();
            break;
        case 2:
            setMapXX();
            break;
        case 3:
            setUpMapXXX();
            break;
        default:
            break;
        }
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

    }

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the
        // map.
        if (mMapView == null) {
            // Try to obtain the map from the SupportMapFragment.

            mMapView = ((SupportMapFragment) getActivity()
                    .getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMapView != null) {
                setUpMap();
                showMap(maptype);
            }
        }
    }

    private void setUpMap() {
        mMapView.setMyLocationEnabled(true);
    }

    // Setting up map for MyProfile Page
    private void setMapX() {
        // Your Code for adding Markers
    }

    // Setting up map for MyProfile Page
    private void setMapXX() {
        // Your Code for adding markers
    }


    public class TouchableWrapper extends FrameLayout {

        public TouchableWrapper(Context context) {
            super(context);
        }

        @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
            switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                this.getParent().requestDisallowInterceptTouchEvent(true);
                break;
            case MotionEvent.ACTION_UP:
                this.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }
            return super.dispatchTouchEvent(ev);
        }
    }

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

        try {
            SupportMapFragment f = (SupportMapFragment) getFragmentManager()
                    .findFragmentById(R.id.map);
            if (f != null)
                getFragmentManager().beginTransaction().remove(f).commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public View getView() {
        if (view != null) {
            return view;
        }
        return super.getView();
    }



    private void setUpMapXXX() {
        // Your Code for adding Markers
    }

}
我也有同样的问题(google maps v2在一个选项卡中只显示了一个灰色网格,但如果我将其作为一个没有选项卡的主要活动加载,它就会工作)

然后我添加了mMapFragment.onResume(),现在它在一个选项卡中工作!试试这个:

mMapFragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
mMapFragment.onResume(); // needed to get the map to display immediately

我在这里找到了解决方案:

只要使用这个类

public class MapFragment extends SupportMapFragment {

    GoogleMap mapView;
    private Context context;

    @Override
    public void onCreate(Bundle arg0) {
            super.onCreate(arg0);
    }

    @Override
    public View onCreateView(LayoutInflater mInflater, ViewGroup arg1,
                    Bundle arg2) {
            View view = super.onCreateView(mInflater, arg1, arg2);
              setMapTransparent((ViewGroup) view);
              return view;
    }

    private void setMapTransparent(ViewGroup group) {
            int childCount = group.getChildCount();
            for (int i = 0; i < childCount; i++) {
            View child = group.getChildAt(i);

                    if (child instanceof ViewGroup) {
                        setMapTransparent((ViewGroup) child);
                    } else if (child instanceof SurfaceView) {
                        child.setBackgroundColor(0x00000000);
                    }
                }
            }

    @Override
    public void onInflate(Activity arg0, AttributeSet arg1, Bundle arg2) {
            super.onInflate(arg0, arg1, arg2);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            context = getActivity();
            mapView = getMap();

            }
}
公共类MapFragment扩展了SupportMapFragment{
谷歌地图地图视图;
私人语境;
@凌驾
创建公共void(包arg0){
super.onCreate(arg0);
}
@凌驾
创建视图上的公共视图(LayoutFlater mInflater,视图组arg1,
捆绑包arg2){
View=super.onCreateView(mInflater,arg1,arg2);
setMapTransparent((视图组)视图);
返回视图;
}
私有void setMapTransparent(视图组){
int childCount=group.getChildCount();
for(int i=0;i
使用
选项卡活动
?请发布一些代码。上面的代码我用于两个选项卡,但我使用不同的布局名称。我确实坚持解决选项卡中重叠的地图碎片,如果你有任何解决方案,请帮助我。我有相同的问题,使用上面的代码,它运行良好,解决了mapv2+选项卡问题…是的,但如何在我的活动中使用片段类。请查看xml布局。我在map_fragg=(LinearLayout)view.findViewById(R.id.map_fragg)中发现您的类有错误;我在两个不同的选项卡上打开我的地图活动,并处理一些条件。在“地图”选项卡上,用户显示完整地图视图,在“搜索”选项卡上,用户使用editbox显示相同的地图以搜索任何位置。但其重叠旧地图bro。我在这个问题上坚持了4天,但没有得到任何完美的解决方案,所以请帮我解决这个问题。非常感谢你,兄弟。来聊天室吧
public class MapFragment extends SupportMapFragment {

    GoogleMap mapView;
    private Context context;

    @Override
    public void onCreate(Bundle arg0) {
            super.onCreate(arg0);
    }

    @Override
    public View onCreateView(LayoutInflater mInflater, ViewGroup arg1,
                    Bundle arg2) {
            View view = super.onCreateView(mInflater, arg1, arg2);
              setMapTransparent((ViewGroup) view);
              return view;
    }

    private void setMapTransparent(ViewGroup group) {
            int childCount = group.getChildCount();
            for (int i = 0; i < childCount; i++) {
            View child = group.getChildAt(i);

                    if (child instanceof ViewGroup) {
                        setMapTransparent((ViewGroup) child);
                    } else if (child instanceof SurfaceView) {
                        child.setBackgroundColor(0x00000000);
                    }
                }
            }

    @Override
    public void onInflate(Activity arg0, AttributeSet arg1, Bundle arg2) {
            super.onInflate(arg0, arg1, arg2);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            context = getActivity();
            mapView = getMap();

            }
}