2010년 8월 2일 월요일

구글맵 API 활용하기 - (4) 위성 지도로 보이기

위성 지도 보이기

MapActivity에서 MapView 객체 가져오기

MapActivity 소스코드 내에서 findViewById 메서드를 이용하여 MapView객체의 레퍼런스를 찾아오기 위하여 android:id 속성을 추가한다.

변경할 파일은 <PROJECT>/res/layout/main.xml이다.

  1. <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <com.google.android.maps.MapView
            android:id="@+id/testMapView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:enabled="true"
            android:clickable="true"
            android:apiKey="03d0eYuU20SMHZARFYNbqBRkKERXqVPMMieAk8g"
            />

    </LinearLayout>

 

<PROJECT>/src/com.jjis.test/R.java 파일에 id와 관련된 속성이 inline class로 생성되었음을 알 수 있다.

그렇다면 생성된 ID를 이용해서 MapView 객체의 레퍼런스를 가져 오도록 findById 메서드를 이용해 보자. 아래와 같이 맴버 변수로 MapView 를 하나 선언하고 onCreate 메서드에 fiewViewById를 호출해서 mapView 변수에 할당하자. 여기서 View를 찾기위한 ID는 R.java의 R.id.testMapView를 이용할 수 있다.

 

  1. package com.jjis.test;

    import android.os.Bundle;

    import com.google.android.maps.MapActivity;
    import com.google.android.maps.MapView;

    public class MapTest extends MapActivity {
       
        private MapView mapView;
       
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            mapView = (MapView)findViewById(R.id.testMapView);
        }

        @Override
        protected boolean isRouteDisplayed() {
            // TODO Auto-generated method stub
            return false;
        }

    }

 

MapView의 Satellite 속성 변경

이제 MapActivity에서 지도를 보여주던 MapView의 레퍼런스를 가져 왔으니 단순히 setSatellite 메서드를 이용해서 true속성만 전달해 주면 된다.

  1.     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            mapView = (MapView)findViewById(R.id.testMapView);
  2.         mapView.setSatellite(true);
        }

 

이제 결과를 확인한다

 

 

출처 - http://zbum.springnote.com/pages/2658038

 

 

댓글 없음:

댓글 쓰기