我知道这是一个被问及已经问过的问题,但是我得到了这种奇怪的行为。没有崩溃,但地图不再加载。
我正在尝试将Google地图用于我的Android应用程序。我昨天设法加载我的地图,但今天当我尝试运行应用程序时,我收到以下错误:
08-01 10:40:50.374: I/Google Maps Android API(5605): Failed to contact Google servers. Another attempt will be made when connectivity is established.
08-01 10:41:05.649: E/Google Maps Android API(5605): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
这是我的Activty,我尝试打开地图:
public class LocationActivity extends Activity {
private GoogleMap map;
private RelativeLayout cancel_btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.preview_location);
cancel_btn = (RelativeLayout) findViewById(R.id.cancel_btn);
cancel_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
if (map != null) {
retrieveLocation();
} else {
}
}
@Override
public void onBackPressed() {
map.clear();
super.onBackPressed();
}
private void retrieveLocation() {
Intent intent = getIntent();
String staddress = intent.getStringExtra("location");
Geocoder geocoder = new Geocoder(this, Locale.US);
try {
List<Address> loc = geocoder.getFromLocationName(staddress, 5);
double latitude = loc.get(0).getLatitude();
double longitude = loc.get(0).getLongitude();
map.addMarker(new MarkerOptions().position(
new LatLng(latitude, longitude)).title(staddress));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 12));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(12), 2000, null);
} catch (IOException e) {
Log.e("IOException", e.getMessage());
Toast.makeText(this, "IOException: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
和XML:
<fragment
android:layout_weight="6"
android:id="@+id/map"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="0dp"
class="com.google.android.gms.maps.MapFragment"/>
表现XML:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.captoom"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.back"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<permission
android:name="ro.gebs.captoom.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA" />
<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" />
<application
android:name="ro.gebs.captoom.utils.CaptoomApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="AA_DB_NAME"
android:value="captoom.db" />
<meta-data
android:name="AA_DB_VERSION"
android:value="1" />
<uses-library android:name="com.google.android.maps" />
<activity
android:name="ro.gebs.captoom.activities.HomeActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ro.gebs.captoom.activities.TakePicture" >
</activity>
<activity android:name="ro.gebs.captoom.activities.PreviewPhoto" >
</activity>
<activity android:name="ro.gebs.captoom.activities.AddReceiptActivity" >
</activity>
<activity android:name="ro.gebs.captoom.activities.EditReceiptActivity" >
</activity>
<activity android:name="ro.gebs.captoom.activities.LocationActivity" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAzIsgylRUb3yxrh-9BsgBJcVo0M4UOhyU" />
</application>
</manifest>
我今天更新了我的API Key仍然没有结果......任何想法?
答案 0 :(得分:1)
兄弟,您是否已根据您的Google Api密钥授予所有权限并更改了套餐名称。现在您必须粘贴清单文件代码。