4월 062011
 

 – 개발 프로젝트 생성시 : Bulid Target을 Google APIs 로 할 것…

= AndroidManifest.xml 수정 =


<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android
      package=”kr.pe.kuniz37.GoogleMapB”
      android:versionCode=”1″
      android:versionName=”1.0″>
    <uses-sdk android:minSdkVersion=”9″ />

    <application android:icon=”@drawable/icon” android:label=”@string/app_name”>
        <activity android:name=”.GoogleMaps”
                  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>
        </activity>
       
        <uses-library android:name=”com.google.android.maps” />
    </application>
   
    <uses-permission android:name=”android.permission.INTERNET” />
</manifest>


= res/layout/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 Code Input
 />

Yout Code Input 에는 debug.keystore의 md5 해시를 가져 와야 한다. 운영체제 마다 위치가 다르다.

 윈도우 7의 경우
   keytool -list -keystore /Users/<사용자 명>/.android/debug.keystore
   암호 : android

  인증서 지문(MD5) 에 나와 있는 값을 http://code.google.com/intl/ko-KR/android/maps-api-signup.html 에서 구한다.

= GoogleMaps.java =
 

import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

public class GoogleMaps extends MapActivity {

 @Override
 protected boolean isRouteDisplayed() {
  return false;
 }

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  MapView mapView = (MapView) findViewById(R.id.mapview);
  mapView.setBuiltInZoomControls(true);

  List<Overlay> mapOverlays = mapView.getOverlays();
  Drawable drawable = this.getResources().getDrawable(
    R.drawable.androidmarker);
  HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);

  GeoPoint point = new GeoPoint(19240000, -99120000);
  OverlayItem overlayitem = new OverlayItem(point, “Hola, Mundo!”,    “I’m in Mexico City!”);
  itemizedoverlay.addOverlay(overlayitem);
  mapOverlays.add(itemizedoverlay);

 }
}

= HelloItemizedOverlay.java =

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 ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
 private Context mContext ;

 public HelloItemizedOverlay(Drawable defaultMarker) {
  super(boundCenterBottom(defaultMarker));
 }

 public void addOverlay(OverlayItem overlay) {
  mOverlays.add(overlay);
  populate();
 }

 @Override
 protected OverlayItem createItem(int i) {
  return mOverlays.get(i);
 }

 @Override
 public int size() {
  return mOverlays.size();
 }

 public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
  super(defaultMarker);
  mContext = context;
 }

 @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;
 }
}


= 실행 =
 – 지도가 안나올 경우 한번 기다린다음에 다시 시도하거나 main.xml의 키를 잘 못 입력하였는지 확인한다.


 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(필수)

(필수)