【问题标题】:Google Map v2 hangs with grey screen on loadGoogle Map v2 在加载时挂起并显示灰屏
【发布时间】:2014-03-14 03:04:17
【问题描述】:

我正在尝试在我的模拟器上的子片段中显示 Google 地图。但问题是,当像这样加载地图时,模拟器会随​​着 toast 的持续显示而冻结:

我检查了我的清单文件,重新创建了 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);

    }

ma​​p_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>

【问题讨论】:

    标签: android google-maps genymotion


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 我不明白。使用相同的密钥库路径导出应用程序是什么意思?你能详细说明一下吗?
    • 请创建密钥库并将其用于导出应用程序。右键项目->导出->.....
    • 好的。我很可能会在 10-12 小时后检查并通知您。
    • 谢谢。我为我的应用创建了新的密钥库并签署了 apk。现在地图视图正在显示。
    • 我也面临同样的问题。我不明白“创建密钥库并将其用于导出应用程序。右键单击 proejct->export->”这个。请详细说明。
    【解决方案2】:

    更改您的 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>
    

    【讨论】:

    • 感谢您的回复。我现在无法检查。半天后通知您。
    • 是的,没问题!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多