我是Android开发的新手。请告诉我如何从密钥库生成谷歌地图密钥的密钥。我试过但我在模拟器上得到以下错误。应用程序你好谷歌地图已经意外停止
我的代码是::(HelloGoogleMaps.java)
package com.java4u.android;
import android.os.Bundle;
public class HelloGoogleMaps extends MapActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Hello Google地图清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.java4u.android"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloGoogleMaps" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<uses-library android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.INTERNET" />
</activity>
</application>
</manifest>
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="Your Maps API Key goes here"
/>
Map Activity.java
package com.java4u.android;
import android.app.Activity;
public class MapActivity extends Activity {
protected boolean isRouteDisplayed() {
return false;
}
}
MapView.java
package com.java4u.android;
public class MapView {
public void setBuiltInZoomControls(boolean b) {
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
private MapView findViewById(int mapview) {
// TODO Auto-generated method stub
return null;
}
}
答案 0 :(得分:0)
正如您所说,您需要使用Google Maps API密钥才能使用MapView。查看this page以获取有关如何获取密钥的更多信息。
获取密钥后,将其传递给main.xml中MapView的android:apiKey
属性。
android:apiKey="Your Maps API Key goes here"
答案 1 :(得分:0)
您必须在 main.xml
中添加 Api密钥尝试此链接获取谷歌 Api密钥并显示谷歌地图
http://mobiforge.com/developing/story/using-google-maps-android