无法加载地图。在片段上联系Google服务器时出错

时间:2013-07-25 04:58:14

标签: android google-maps

  1. 我谷歌两天仍然是这个消息。我使用调试密钥进行调试 在我的nexus 7上。
  2. 我不知道哪里出错了。我有正确的密钥,打开正确的api访问
  3. 但我的平板电脑上的谷歌地图仍然空白。
  4. MapsFragment:

        public View onCreateView(LayoutInflater inflater, ViewGroup container,
    
         

    Bundle savedInstanceState){
      查看rootView =   inflater.inflate(R.layout.map_fragment,container,false);         container.removeAllViews(); map =   ((SupportMapFragment)getActivity()       .getSupportFragmentManager()       .findFragmentById(R.id.map))       .getMap();       map.setMyLocationEnabled(真);       map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

       mMapFragment = SupportMapFragment.newInstance();
       FragmentTransaction fragmentTransaction = 
    
         。

    getChildFragmentManager()的BeginTransaction();
      fragmentTransaction.add(R.id.map,mMapFragment);
      fragmentTransaction.commit(); return rootView; }

    清单:

      

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="16" />
    
    <!-- Google Map -->   <permission
          android:name="com.jertt.xxx.permission.MAPS_RECEIVE"
          android:protectionLevel="signature"/>
    <uses-permission android:name="com.jertt.yummymap.permission.MAPS_RECEIVE"/>
    
         

                               

    <!-- end -->
    
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    
    <!-- end -->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.jertt.yummymap.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
        <!-- Google Map API Key -->
    
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyB54eZnUp8Sw*****" />
    
        <!-- end -->
    </application>
    
         

    map_fragment.xml

      

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />
    
         

3 个答案:

答案 0 :(得分:1)

不确定这是不是你的问题,但是我花费了大量的时间来试图解决这个问题。检查权限,重新生成api密钥。最后在另一个对我有用的答案中看到了一个小评论。

重命名debug.keystore文件,然后执行clean,然后构建。这将生成一个新的debug.keystore。和一个新的SHA1指纹。将新指纹插入api控制台,然后重试。

您可以检查的另一件事是查看您尝试访问api的项目的api控制台的“reports”部分。如果您尝试运行项目并且没有该api的流量,则可能是SHA1指纹或您提供的包名称错误。就我而言,这是指纹。

答案 1 :(得分:0)

你的min sdk是14.无需使用SupportMapFragment。使用MapFragment

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment

<fragment 
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="fill_parent"
      android:name="com.google.android.gms.maps.MapFragment"/> 

  GoogleMap  mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                                .getMap();

还缺少权限

 <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"/>
 <!-- The following two permissions are not required to use
 Google Maps Android API v2, but are recommended. -->
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

确保您已按照所有步骤@

https://developers.google.com/maps/documentation/android/

编辑:来自评论

从文档引用

仅当您定位API 12 及更高版本时才使用MapFragment课程。 否则,请使用SupportMapFragment。

答案 2 :(得分:0)

你必须改为:

GoogleMap  mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map))
                            .getMap();

还包括清单文件库:

<uses-library
        android:name="com.google.android.maps"
        android:required="true" />
相关问题