마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

네이버 지도 API 사용시 현재좌푯값 가져올때 궁금한게 있습니다.

0 추천

혹시몰라 소스의 전문입니다. ㅠㅠ

현재 위치를 띄우고 싶은데 어플 가동을 하면 처음에 서울시청쪽이 잡히고 에러가 발생하면서 종료가 됩니다...;

어디가 잘못된 걸까요 ㅠㅠ 로그캣에는 경도와 위도를 가져올 때 에러가 나는것 같은데 ...ㅠㅠ검토 부탁드립니다...



package com.summer_vacation;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.example.summervacation.R;
import com.nhn.android.maps.NMapActivity;
import com.nhn.android.maps.NMapCompassManager;
import com.nhn.android.maps.NMapController;
import com.nhn.android.maps.NMapLocationManager;
import com.nhn.android.maps.NMapView;
import com.nhn.android.maps.NMapView.OnMapStateChangeListener;
import com.nhn.android.maps.NMapView.OnMapViewTouchEventListener;
import com.nhn.android.maps.maplib.NGeoPoint;
import com.nhn.android.maps.nmapmodel.NMapError;
import com.nhn.android.maps.nmapmodel.NMapPlacemark;
import com.nhn.android.mapviewer.overlay.NMapMyLocationOverlay;

public class MapActivity<MapContainerView> extends NMapActivity implements
OnMapStateChangeListener, OnMapViewTouchEventListener {

public static final String API_KEY_VALUE = "a19961093f9020c6b7801ffdb4a16196";
NMapView mMapView = null;
NMapController mMapController = null;
NMapLocationManager mMapLocationManager;
NMapCompassManager mMapCompassManager;
NMapMyLocationOverlay mMyLocationOverlay;
MapContainerView mMapContainerView;
LinearLayout MapContainer;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// TODO Auto-generated method stub

MapContainer = (LinearLayout) findViewById(R.id.map);

mMapView = new NMapView(this);

mMapView.setApiKey(API_KEY_VALUE);

setContentView(mMapView);

mMapView.setClickable(true);

mMapView.setOnMapStateChangeListener(this);
mMapView.setOnMapViewTouchEventListener(this);

mMapController = mMapView.getMapController();
mMapView.setBuiltInZoomControls(true, null);
}

@Override
public void onLongPress(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub

}

@Override
public void onLongPressCanceled(NMapView arg0) {
// TODO Auto-generated method stub

}

@Override
public void onScroll(NMapView arg0, MotionEvent arg1, MotionEvent arg2) {
// TODO Auto-generated method stub

}

@Override
public void onSingleTapUp(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub

}

@Override
public void onTouchDown(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub

}

@Override
public void onTouchUp(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationStateChange(NMapView arg0, int arg1, int arg2) {
// TODO Auto-generated method stub

}

@Override
public void onMapCenterChange(NMapView arg0, NGeoPoint arg1) {
// TODO Auto-generated method stub

}

@Override
public void onMapCenterChangeFine(NMapView arg0) {
// TODO Auto-generated method stub

}

@Override
public void onMapInitHandler(NMapView mapview, NMapError errorInfo) {
// TODO Auto-generated method stub
if (errorInfo == null) { // success
startMyLocation();// 현재위치로 이동
// mMapController.setMapCenter(new NGeoPoint(126.978371,
// 37.5666091),
// 11);
} else { // fail
android.util.Log.e("NMAP",
"onMapInitHandler: error=" + errorInfo.toString());
}

}

private void startMyLocation() {
// TODO Auto-generated method stub
mMapLocationManager = new NMapLocationManager(this);
mMapLocationManager
.setOnLocationChangeListener(onMyLocationChangeListener);

boolean isMyLocationEnabled = mMapLocationManager
.enableMyLocation(true);

if (!isMyLocationEnabled) {
Toast.makeText(MapActivity.this,
"Please enable a My Location source in system settings",
Toast.LENGTH_LONG).show();

Intent goToSettings = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(goToSettings);
finish();
} else {

}

}

private void stopMyLocation() {
if (mMyLocationOverlay != null) {
mMapLocationManager.disableMyLocation();

if (mMapView.isAutoRotateEnabled()) {
mMyLocationOverlay.setCompassHeadingVisible(false);

mMapCompassManager.disableCompass();

mMapView.setAutoRotateEnabled(false, false);

MapContainer.requestLayout();
}
}
}

@Override
public void onZoomLevelChange(NMapView arg0, int arg1) {
// TODO Auto-generated method stub

}

private final NMapActivity.OnDataProviderListener onDataProviderListener = new NMapActivity.OnDataProviderListener() {

@Override
public void onReverseGeocoderResponse(NMapPlacemark placeMark, NMapError errInfo) {

if (errInfo != null) {
Log.e("myLog", "Failed to findPlacemarkAtLocation: error=" + errInfo.toString());
Toast.makeText(MapActivity.this, errInfo.toString(), Toast.LENGTH_LONG).show();
return;
}else{
Toast.makeText(MapActivity.this, placeMark.toString(), Toast.LENGTH_LONG).show();
}

}

};

private final NMapLocationManager.OnLocationChangeListener onMyLocationChangeListener = new NMapLocationManager.OnLocationChangeListener() {

@Override
public boolean onLocationChanged(NMapLocationManager locationManager,
NGeoPoint myLocation) {

if (mMapController != null) {
mMapController.animateTo(myLocation);
}
Log.d("myLog", "myLocation lat " + myLocation.getLatitude());
Log.d("myLog", "myLocation lng " + myLocation.getLongitude());

findPlacemarkAtLocation(myLocation.getLongitude(),
myLocation.getLatitude());
// 위도경도를 주소로 변환

return true;
}

@Override
public void onLocationUnavailableArea(NMapLocationManager arg0,
NGeoPoint arg1) {
// TODO Auto-generated method stub

Toast.makeText(MapActivity.this,
"Your current location is unavailable area.",
Toast.LENGTH_LONG).show();

stopMyLocation();


}

@Override
public void onLocationUpdateTimeout(NMapLocationManager arg0) {
// TODO Auto-generated method stub

// stop location updating
Runnable runnable = new Runnable() {
public void run() {
stopMyLocation();
}
};
runnable.run();

Toast.makeText(MapActivity.this,
"Your current location is temporarily unavailable.",
Toast.LENGTH_LONG).show();

}

};

}

 

개발하는캐미 (230 포인트) 님이 2014년 8월 31일 질문
소스도 소스지만... 에러 메세지를 보여주세요.

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...