谷歌地图v2在加载时挂起灰色屏幕

时间:2014-03-14 03:04:17

标签: android google-maps genymotion

我正在尝试在我的模拟器上显示子片段内的Google地图。但问题是,当地图加载时,模拟器会随​​着烤面包一起冻结而冻结:

enter image description here

我已经检查了我的清单文件,重新创建了API密钥和debug.keystore。但它还没有奏效。请告诉我如何解决这个问题。感谢。

**注意:**我正在测试Genymotion模拟器 - Galaxy S2 API 10(2.3.7)。 Google Play服务已安装在模拟器上。

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.estytic.clubinthechi"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.INTERNET" />
    <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="com.example.project.permission.MAPS_RECEIVE"/>

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <permission
        android:name="com.example.project.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission android:name="android.permission.CALL_PHONE"/>

    <application
        android:hardwareAccelerated="false"
        android:logo="@drawable/ic_drawer1"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data  android:name="com.google.android.maps.v2.API_KEY"
android:value="api-key"/>

        <uses-library android:name="com.google.android.maps" />
        <activity
            android:name="com.example.project.MainActivity"
            android:label="@string/app_name"
            android:clearTaskOnLaunch="true"  
android:stateNotNeeded="true"
android:theme="@style/Theme.AppCompat" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

MapFragment.java

public class MapFragmentClass extends Fragment implements GooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListener,LocationListener  {

    //to extract current loc
    private LocationClient locationclient;
    private LocationRequest locationrequest;
    SupportMapFragment mapFragment;
    GoogleMap map;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.map_fragment, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onViewCreated(view, savedInstanceState);

          FragmentManager fm = getChildFragmentManager();
            mapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
            if (mapFragment == null) {
                mapFragment = SupportMapFragment.newInstance();
                fm.beginTransaction().replace(R.id.map, mapFragment).commit();
                fm.executePendingTransactions();

                delayMapLoading();

            }

    }

    void delayMapLoading()
    {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() 
        {
           @Override
           public void run() {
               map = mapFragment.getMap();

               if(map != null)
                {
                    Log.i("MSG","map is not null");
                    map.setMyLocationEnabled(true);
                 map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

                }

               else {
                   // handler.postDelayed(this, 500);
               }
           }
          }, 1000);

    }

map_fragment.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="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >
 <FrameLayout android:id="@+id/map"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1.03"
   android:name="com.google.android.gms.maps.SupportMapFragment" />

</LinearLayout>

2 个答案:

答案 0 :(得分:0)

如果您创建了debug.keystore,那么您是否使用相同的密钥库路径导出应用程序?

我认为您不必导出您的应用..

Please export your app with same keystore which is created ..

我希望你解决了你的问题。

答案 1 :(得分:0)

更改map_fragment.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="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >
 <FrameLayout android:id="@+id/map"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1.03"
   android:name="com.google.android.gms.maps.SupportMapFragment" />

</LinearLayout> 

<?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="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical" >

     <fragment android:id="@+id/map"
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:layout_weight="1.03"
       android:name="com.google.android.gms.maps.SupportMapFragment" />

    </LinearLayout>