1) System confirm path
내컴퓨터 > 고급 > 환경변수 > path >
Add this path :
C:\android\tools;C:\Program Files\Java\jdk1.6.0_17\bin
2) Get the API Key
C:\>cd C:\Documents and Settings\%username%\.android\
C:\Documents and Settings\jp\.android>keytool -list -alias androiddebugkey -keys
tore debug.keystore -storepass android -keypass android
androiddebugkey, 2010. 4. 12, PrivateKeyEntry,
인증서 지문(MD5): B1:B9:5F:01??????????????????:27:BF:29:FA:67:5C:26
http://code.google.com/intl/ko/android/maps-api-signup.html
Sign Up for the Android Maps API
3) Create AVD
over level Google APIs Level 6
4) Create project
5) /HelloMyMap/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.HelloMyMap"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".HelloMyMap"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="6" />
</manifest>
6) /HelloMyMap/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="00Q8dPkiSL???????????????v-PfctrXmOFA"
/>
</RelativeLayout>
7) /HelloMyMap/src/my/HelloMyMap/HelloItemizedOverlay.java
package my.HelloMyMap;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
public class HelloItemizedOverlay extends ItemizedOverlay {
private Context mContext;
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
// TODO Auto-generated constructor stub
mContext = context;
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return mOverlays.get(i);
}
@Override
public int size() {
// TODO Auto-generated method stub
return mOverlays.size();
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
8) /HelloMyMap/src/my/HelloMyMap/HelloMyMap.java
package my.HelloMyMap;
import java.util.List;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.ZoomControls;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class HelloMyMap extends MapActivity {
List<Overlay> mapOverlays;
Drawable drawable;
HelloItemizedOverlay itemizedOverlay;
LinearLayout linearLayout;
MapView mapView;
ZoomControls mZoom;
@Override
protected boolean isRouteDisplayed() {
return false;
}
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
GeoPoint p=new GeoPoint(53458671,-2267346);
MapController mc=mapView.getController();
mc.animateTo(p);
mc.setZoom(5);
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.androidmarker);
itemizedOverlay = new HelloItemizedOverlay(drawable,this);
OverlayItem overlayitem = new OverlayItem(p, "Hello", "Man Utd.");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
}
}
9) Result Images
Reference http://www.androidside.com
댓글 없음:
댓글 쓰기