Android-谷歌地图APIv2在片段中仅显示黑色sreen

Android-谷歌地图APIv2在片段中仅显示黑色sreen,android,google-maps-android-api-2,Android,Google Maps Android Api 2,我的应用程序代码中有一个非常奇怪的情况,也许有人能帮我解决这个问题。问题在于它包含了谷歌地图。由于规范的原因,我有两种不同的映射实现: MapActivity-扩展ActionBarActivity MapFragment-扩展Fragment 我使用的是API10 两个实现都使用相同的MapAPI键和相同的布局 在MapActivity中,一切正常,map正在显示,LogCat中没有错误。然而,在MapFragment中,情况完全不同 我没有地图-更准确地说,地图是黑色的,我在左下角有谷歌

我的应用程序代码中有一个非常奇怪的情况,也许有人能帮我解决这个问题。问题在于它包含了谷歌地图。由于规范的原因,我有两种不同的映射实现:

  • MapActivity-扩展
    ActionBarActivity
  • MapFragment-扩展
    Fragment
我使用的是
API10

两个实现都使用相同的MapAPI键和相同的布局

在MapActivity中,一切正常,map正在显示,LogCat中没有错误。然而,在MapFragment中,情况完全不同

我没有地图-更准确地说,地图是黑色的,我在左下角有谷歌标志和放大/缩小控制器,但没有地图,只有黑屏和LogCat中的错误:

Could not find class 'maps.ae.i', referenced from method maps.af.al.a
这是我的MapFragment源代码中最重要的片段:

public class MapFragment extends Fragment {

    private GoogleMap mMap;

    private static View view;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (view != null) {
            ViewGroup parent = (ViewGroup) view.getParent();
            if (parent != null)
                parent.removeView(view);
        }
        try {
            view = inflater.inflate(R.layout.activity_map, container, false);
        } catch (InflateException e) {
            /* map is already there, just return view as it is */
        }

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        checkGooglePlayServices();
        if (getActivity().getIntent().hasExtra("extra")) {
            setMarkers(getActivity().getIntent());
        } else {
            setMarkers();
        }
    }

    private void setUpMapIfNeeded() {
        if (mMap != null) {
            return;
        }
        mMap = ((SupportMapFragment) getFragmentManager()
                .findFragmentById(R.id.map)).getMap();
        if (mMap == null) {
            return;
        }
        // Initialize map options.
        LatLng startPoz = new LatLng(52.34, 18.9);
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(startPoz, 6));
    }

    private void checkGooglePlayServices() {
        int status;
        status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
        if (status != ConnectionResult.SUCCESS) {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, getActivity(),
                    69);
            dialog.show();
        } else {
            setUpMapIfNeeded();
        }
    }
这是activity_map.xml(同样用于MapActivity和MapFragment):

进入

这是include_map.xml的代码:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    map:mapType="normal" />

此外,我还选择了
class=“com.google.android.gms.maps.SupportMapFragment”
,而不是
android:name=“com.google.android.gms.maps.SupportMapFragment”
,并且没有任何更改


我想这就是我能告诉你的一切。希望有人能帮我解决这个问题。

尝试使用以下代码获取地图:

SupportMapFragment smf = (SupportMapFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.map);

如果您使用的是
SupportMapFragment
,则需要使用
SupportFragmentManager

获取它,不幸的是,它根本不起作用。还是这个问题。你找到解决办法了吗?我现在也遇到了同样的问题,需要一个有用的提示。@user2145222。结果表明,错误是在Map和ZXing库之间进行扫描。我所做的,我把中兴也变成了碎片,现在一切都很好。谢谢你的回复。不幸的是,我没有使用ZXing,所以我一定是以其他方式造成了这个问题,尽管如此,知道这一点对于将来的参考是有用的。
view = inflater.inflate(R.layout.inlude_map, container, false);
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    map:mapType="normal" />
SupportMapFragment smf = (SupportMapFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.map);