我正在尝试让 Android ' Google Maps Android API v2 ' 的示例代码工作。我得到的项目没有错误。但是,当我尝试在 Everpad 设备中运行该应用程序时,该应用程序立即崩溃。这是 :
- java代码
package com.dvp.android.gallery;
public class GPS extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gps);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions().position(KIEL).title("Kiel").snippet("Kiel is cool").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}
清单:
<application android:icon="@drawable/ic_bardo" android:label="@string/app_name"> <activity android:name=".Acceuil" 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=".Objets" android:label="Objets"> </activity> <activity android:name=".GPS" android:label="GPS"> </activity> <activity android:name=".Detail" android:label="Detail"></activity> <activity android:name=".Galeries" android:label="Galeries" /> <activity android:name=".Evennements" android:label="Evennements"/> <activity android:name=".Infos" android:label="Infos"/> </application> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyA0HMTTGLqlYaq6jOuS0imbjt7GmUHyK0c"/> <uses-sdk android:minSdkVersion="11" /> <uses-permission android:name="com.dvp.android.gallery.maps.permission.MAPS_RECEIVE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/> <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" /> </manifest>
- 日志输出:
466: E/AndroidRuntime(5542): 在 com.dvp.android.gallery.GPS.onCreate(GPS.java:23) 09-27 12:42:49.466: E/AndroidRuntime(5542): 在 android.app.Activity .performCreate(Activity.java:4465) 09-27 12:42:49.466: E/AndroidRuntime(5542): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 09-27 12:42:49.466: E /AndroidRuntime(5542): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 09-27 12:42:49.466: E/AndroidRuntime(5542): ... 11 更多 09-27 12:42:49.466 :E / AndroidRuntime(5542):原因:java.lang.RuntimeException:找不到API密钥。检查是否在 AndroidManifest.xml 的元素中 09-27 12:42:49.466: E/AndroidRuntime(5542): at maps.ag.bb.a(Unknown Source) 09-27 12:42:49.466: E/AndroidRuntime (5542):在 maps.ag.bb.a(未知来源)09-27 12:42:49.466:
XML:
<LinearLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".GPS" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</LinearLayout>
请帮我 。谢谢