how to display google map on android emulator?
i am new to android development.please tell me how to generate key for google map keys from key store.I tried but i am getting the following error on the emulator.sorry the application hello google maps has stopped unexpectly
my codes are:: (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 map manifest
<?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;
}
}
As you already said, you need a Google Maps API key to use the MapView. Check this page for further information on how to get a key.
After getting the key, pass it to the android:apiKey
attribute of the MapView in main.xml.
android:apiKey="Your Maps API Key goes here"
hi you have to add Api key in a main.xml
try this link get google Api key and display google map
http://mobiforge.com/developing/story/using-google-maps-android
精彩评论