0

我已经实现Android的谷歌地图V2在我的应用程序和它的大多数我所测试的设备(银河王牌此外,7英寸的Galaxy Tab键,索尼的Xperia Z^)的正常工作。但它不适用于HTC Desire的。我已经交叉验证了Google Play服务也安装在该设备中。我大量寻找解决方案。下面是我的实现。下面无法加载Android的谷歌地图V2

public class MainActivity extends FragmentActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
     SupportMapFragment fragment = new SupportMapFragment(); 
     getSupportFragmentManager().beginTransaction() 
       .add(android.R.id.content, fragment).commit();   
} 
} 

是activity_main.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/the_map" 
android:name="com.google.android.gms.maps.SupportMapFragment" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
map:cameraTilt="45" 
map:cameraZoom="2" /> 

,这里是清单文件。

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

<permission 
    android:name="com.raj.googlemapsv2test.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature" /> 

<uses-permission android:name="com.raj.googlemapsv2test.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-feature 
    android:glEsVersion="0x00020000" 
    android:required="true" /> 

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="17" /> 

<application 
    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="AIzaSyDD6bvUVkTk2UzOLpojdeBtlh5xBYDhy6E" /> 

    <activity 
     android:name="com.raj.googlemapsv2test.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> 
</application> 

</manifest> 

当我检查日志其显示以下错误行。

Could not find class 'maps.i.k', referenced from method maps.z.ag.a 
Failed to load map. Could not contact Google servers. 
Failed to load map. Could not contact Google servers. 

,最后用一个小疑问我更新了设备的护目镜地图应用之后,它的工作。 所以我想向用户显示一个警报,以便在任何设备上发现这种问题时进行更新。但无法知道如何检查这一点。因此,任何一个可以建议一些方法来找到护目镜地图应用Android的护目镜播放服务在设备是否的支持版本,此Android的护目镜地图V2与否。

任何解决方案,将不胜感激。

+0

我在HTC Desire上发现了一个类似的问题,除了我的说“找不到类maps.af.k”,从方法maps.ag.an.a引用“。它还表示它“无法解析Lmaps/p/w的超类;(734)”。像你说的那样更新Google地图应用并没有解决问题,我仍然看不到地图。 – Ogre 2013-08-09 05:38:12

回答

6

您可以将此代码添加到您的onResume方法中。它会检查用户是否拥有Google Play服务的更新版本,如果用户没有,则会显示将他重定向到Google Play的弹出窗口。

@Override 
protected void onResume() { 
    super.onResume(); 
    int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); 
    if(errorCode != ConnectionResult.SUCCESS && GooglePlayServicesUtil.isUserRecoverableError(errorCode)){ 
     Dialog d = GooglePlayServicesUtil.getErrorDialog(errorCode, this, 0, new OnCancelListener() { 
      @Override 
      public void onCancel(DialogInterface dialog) { 
       //As my application does a heavy use of maps, if the user cancels the dialog, I just finish the FragmentActivity 
       MainFragmentActivity.this.finish(); 
      } 
     }); 
     d.show(); 
    } 
} 

希望有帮助,欢呼!

+0

我试过这个,它似乎没有解决问题。 – Ogre 2013-08-09 05:38:37

0
@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 
    FragmentManager fm = getChildFragmentManager(); 

    supportMapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map); 
    if (supportMapFragment == null) { 
     supportMapFragment = SupportMapFragment.newInstance(); 
     fm.beginTransaction().replace(R.id.map, supportMapFragment).commit(); 
    } 
} 

此时谷歌播放服务不初始化如此获取地图和添加要它什么都在的onResume()或在onStart()

@Override 
public void onResume() { 
    super.onResume(); 
    if (gMap == null) { 
     supportMapFragment.getMapAsync(this); 
    } 
} 

添加此之后ü需要实现OnMapReadyCallback 。并做任何你喜欢做的操作与地图。