我尝试安装tutorial中的项目:
一切都好但是在运行项目时,logcat说:
"找不到类' maps.ag.l',引用方法maps.ah.an.a"
地图是空的,logcat说:
"无法加载地图。联系Google服务器时出错这可能是一个身份验证问题(但可能是由于网络错误)。
我更改了" in.wptrafficanalyzer.locationgooglemapv2demo" to" it.appatwork"我有我的sha1的android map apiV2的apikey。
我有android 2.3.3
请帮助我!
Mainactivity:
package it.appatwork.locationgooglemapv2demo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable (getApplicationContext());
if(status == ConnectionResult.SUCCESS) {
System.out.println("ok");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
activity_main.xml中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
AndoridManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.appatwork.locationgooglemapv2demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"/>
<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-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="it.appatwork.locationgooglemapv2demo.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBgkEwv0Z4O2t27avrve_33N33QY0wHNXg"/>
</application>
</manifest>
更新
这是logcat输出:
07-24 23:11:40.849: W/dalvikvm(6472): VFY: unable to resolve instance field 24
07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/p/w; (718)
07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/p/w;' failed
07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/aq/as; (5347)
07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/aq/as;' failed
07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/ag/l; (4576)
07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/ag/l;' failed
07-24 23:11:41.149: E/dalvikvm(6472): Could not find class 'maps.ag.l', referenced from method maps.ah.an.a
07-24 23:11:41.149: W/dalvikvm(6472): VFY: unable to resolve new-instance 4420 (Lmaps/ag/l;) in Lmaps/ah/an;
07-24 23:11:41.359: I/ApplicationPackageManager(6472): cscCountry is not German : WIN
07-24 23:11:47.069: W/Google Maps Android API(6472): Please add <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> into AndroidManifest.xml to ensure correct behavior under poor connectivity conditions.
07-24 23:11:47.069: I/Google Maps Android API(6472): Failed to contact Google servers. Another attempt will be made when connectivity is established.
07-24 23:11:59.009: W/IInputConnectionWrapper(6472): getExtractedText on inactive InputConnection
07-24 23:11:59.009: W/IInputConnectionWrapper(6472): getExtractedText on inactive InputConnection
07-24 23:12:02.289: E/Google Maps Android API(6472): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
答案 0 :(得分:0)
首先,您所描述的两个问题并不相关,您的主要问题在于:
无法加载地图。联系Google服务器时出错这可能是 身份验证问题(但可能是由于网络错误)。
这意味着您在清单文件中的权限存在某种问题,或者在Google API控制台中配置了您的权限。
请仔细阅读这两篇博客Google Maps API V2 key和Google Maps API V2的所有步骤,并提交所有步骤,如果您仍然遇到问题,请在此处发布您的代码和更新的logcat消息。
<强>更新强>
您打包名称:
package="it.appatwork.locationgooglemapv2demo"
与您在权限中指定的包名称不匹配:
permission
android:name="it.appatwork.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="it.appatwork.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"/>
我认为这是区分大小写的,所以请尝试将其更改为:
permission
android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"/>