Google Maps v2空白网格

时间:2013-08-31 16:21:25

标签: android google-maps-android-api-2

我正在尝试让Google地图在Action Bar标签中工作,但我只得到一个空白网格(不是完全空白),没有任何图块。与此选项卡无关的logcat错误(映射键工作)。

tab3.java:

    package codekappa.smartlocation;

import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.app.ActionBar.Tab;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ActionBar;

public class FragmentsTab3 extends Fragment implements ActionBar.TabListener {
    private GoogleMap map;
    private MapView mapView;
    private Fragment mFragment;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment3, container, false);

        // Gets the MapView from the XML layout and creates it
        mapView = (MapView) v.findViewById(R.id.map);
        mapView.onCreate(savedInstanceState);
        // Gets to GoogleMap from the MapView and does initialization stuff
        map = mapView.getMap();
        map.getUiSettings().setMyLocationButtonEnabled(false);
        map.setMyLocationEnabled(true);

        // Needs to call MapsInitializer before doing any CameraUpdateFactory calls
        try {
            MapsInitializer.initialize(this.getActivity());
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }

        return v;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActivity().setContentView(R.layout.fragment3);
    }

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
        mFragment = new FragmentsTab3();
        // Attach fragment3.xml layout
        ft.add(android.R.id.content, mFragment);
        ft.attach(mFragment);
    }

    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
        // Remove fragment3.xml layout
        ft.remove(mFragment);
    }

    public void onTabReselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

}

Fragment3.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:name="com.google.android.gms.maps.MapFragment">

    <com.google.android.gms.maps.MapView android:id="@+id/map"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" />

</LinearLayout>

的Manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="codekappa.smartlocation"
    android:versionCode="1"
    android:versionName="1.0" >
<permission
        android:name="codekappa.smartlocation.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>

    <uses-permission android:name="codekappa.smartlocation.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
    <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="18" />

    <application


        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Holo.NoActionBar" >

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyDLX4a6pyeGsDocAHhjGOKSyeAE0aunHbA"/>

        <activity
            android:name="codekappa.smartlocation.AndroidTabLayoutActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

不确定这里有什么问题,想法?

2 个答案:

答案 0 :(得分:2)

我遇到了类似的问题,我通过添加onResume()解决了我的问题。

@Override
public void onResume() {
    mapView.onResume();
    super.onResume();
}

答案 1 :(得分:0)

您缺少另一个元数据元素。请在Blank map with Google Map V2 and SupportMapFragment (and no, this is not an API key issue)

中查看我的回答