본문 바로가기

Computer Science/Android

네이버 모바일맵 띄우기

모바일맵 라이브러리 다운받아서 추가해야하고

api키만 넣어서 그대로 실행해주면 화면만 잘떠요


-------------------------------------------------------------------------------------------

public class Map extends NMapActivity {

private static final String API_KEY = "발급받은키";

private NMapView mMapView;

private NMapController mMapController;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//네이버 지도 MapView를 생성해준다.

mMapView = new NMapView(this);

//지도에서 ZoomControll을 보여준다

mMapView.setBuiltInZoomControls(true, null);

//네이버 OPEN API 사이트에서 할당받은 KEY를 입력하여 준다.

mMapView.setApiKey(API_KEY);

//이 페이지의 레이아웃을 네이버 MapView로 설정해준다.

setContentView(mMapView);

//네이버 지도의 클릭이벤트를 처리 하도록한다.

mMapView.setClickable(true);

//맵의 상태가 변할때 이메소드를 탄다.

mMapView.setOnMapStateChangeListener(new NMapView.OnMapStateChangeListener() {

public void onZoomLevelChange(NMapView arg0, int arg1) {

}

public void onMapInitHandler(NMapView arg0, NMapError arg1) {

if (arg1 == null)

{

                //  표시해줄 위치 

mMapController.setMapCenter(new NGeoPoint(126.978371, 37.5666091), 11);

}

else

{

Toast.makeText(getApplicationContext(), arg1.toString(), Toast.LENGTH_SHORT).show();

}

}

public void onMapCenterChangeFine(NMapView arg0) {

}

public void onMapCenterChange(NMapView arg0, NGeoPoint arg1) {

}

public void onAnimationStateChange(NMapView arg0, int arg1, int arg2) {

}

});

//맵뷰의 이벤트리스너의 정의.

mMapView.setOnMapViewTouchEventListener(new NMapView.OnMapViewTouchEventListener() {

public void onTouchDown(NMapView arg0, MotionEvent arg1) {

}

public void onSingleTapUp(NMapView arg0, MotionEvent arg1) {

}

public void onScroll(NMapView arg0, MotionEvent arg1, MotionEvent arg2) {

}

public void onLongPressCanceled(NMapView arg0) {

}

public void onLongPress(NMapView arg0, MotionEvent arg1) {

}

});

mMapController = mMapView.getMapController();

super.setMapDataProviderListener(new OnDataProviderListener() {

public void onReverseGeocoderResponse(NMapPlacemark arg0, NMapError arg1) {

}

});

}

}

'Computer Science > Android' 카테고리의 다른 글

db 만들기  (0) 2012.07.13
안드로이드 xml 파싱  (0) 2012.07.13
서울시 open api 작은 팁!!  (0) 2012.07.09
이클립스 단축키 모음  (0) 2012.05.22
4] 이번에는 레이아웃 입니다  (0) 2012.04.26