我在 Android 中创建了一个基于谷歌地图的应用程序。我有一个 API 密钥,它在模拟器中成功运行,但是当我在设备上运行它时,它显示强制关闭消息。有人可以解释一下如何获取在设备上使用的 API 密钥,以及我是否必须获得专门用于设备使用的 API 密钥?
我的Java代码:
setContentView(R.layout.mapview);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
String coordinates[] = {"9.966667", "78.166667"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
GeoPoint p = new GeoPoint((int) (lat * 1E6),(int) (lng * 1E6));
MapController mapController = mapView.getController();
mapController.setCenter(p);
mapController.animateTo(p);
mapController.setZoom(12);
我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="myapikey" />
</LinearLayout>
日志错误:
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x1080215
这个问题是我项目的障碍,所以在解决之前我无法继续前进。