NMapViewerResourceProvider를 import가 안되는거같은데 뭐가문제일까요?
위도 경도는 잘 받아오는데요...
아래에서
findPlacemarkAtLocation() could not be invoked prior to setMapDataProviderListener().
에러가 터지네요
그래서 oncreate()부분에서
@Overridepublic void setMapDataProviderListener(OnDataProviderListener onDataProviderListener) {
super.setMapDataProviderListener(onDataProviderListener);
}해줘도 똑같군요 ㅜㅠ
혹시 몰라서 소스 복붙했습니다. 아래에. 따로 레이아웃 쓴게없어서 보고 복붙해도 실행될거에요.
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.nhn.android.maps.NMapActivity;
import com.nhn.android.maps.NMapLocationManager;
import com.nhn.android.maps.NMapOverlay;
import com.nhn.android.maps.NMapOverlayItem;
import com.nhn.android.maps.NMapView;
import com.nhn.android.maps.NMapView.OnMapStateChangeListener;
import com.nhn.android.maps.maplib.NGeoPoint;
import com.nhn.android.maps.nmapmodel.NMapError;
import com.nhn.android.maps.NMapController;
import com.nhn.android.maps.nmapmodel.NMapPlacemark;
import com.nhn.android.mapviewer.overlay.NMapCalloutOverlay;
import com.nhn.android.mapviewer.overlay.NMapOverlayManager;
public class MainActivity extends NMapActivity implements NMapView.OnMapViewTouchEventListener ,OnMapStateChangeListener,NMapOverlayManager.OnCalloutOverlayListener {
@Override
public void setMapDataProviderListener(OnDataProviderListener onDataProviderListener) {
super.setMapDataProviderListener(onDataProviderListener);
}
private boolean per=false;
NMapView mMapView = null;
NMapController mMapController = null;
private NMapLocationManager mMapLocationManager;
public void startMyLocation() {
mMapLocationManager = new NMapLocationManager(MainActivity.this);
mMapLocationManager
.setOnLocationChangeListener(onMyLocationChangeListener);
boolean isMyLocationEnabled = mMapLocationManager
.enableMyLocation(true);
if (!isMyLocationEnabled) {
Intent goToSettings = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(goToSettings);
finish();
} else {
}
}
//LinearLayout MapContainer;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);// create map view
checkDangerousermissions();
//MapContainer = (LinearLayout)findViewById(R.id.navermap);
mMapView = new NMapView(this);// set a registered API key for Open MapViewer Library
mMapView.setApiKey("uDg8DaCVRq5KnivRwm3z");// set the activity content to the map view
setContentView(mMapView);// initialize map view
mMapView.setClickable(true);// register listener for map state changes
mMapView.setOnMapStateChangeListener(this);
mMapView.setBuiltInZoomControls(true, null);
mMapController = mMapView.getMapController();
mMapView.setOnMapStateChangeListener(new OnMapStateChangeListener() {
public void onZoomLevelChange(NMapView arg0, int arg1) {
}
// TODO Auto-generated method stub
public void onAnimationStateChange(NMapView arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onMapInitHandler(NMapView nMapView, NMapError nMapError) {
Log.e("main", "맵들어옴" + nMapView + ",+" + nMapError);
// TODO Auto-generated method stub
if (nMapError == null) { // success
startMyLocation();
//startMyLocation();
//mMapController.setMapCenter(new NGeoPoint(126.89040777, 37.50999167), 13);
} else { // fail
Log.e("NMAP", "onMapInitHandler: error=" </span>+ nMapError.toString());<br> }<br> }<br><br> <span style="color:#000080;font-weight:bold;">public void onMapCenterChange(NMapView arg0, NGeoPoint arg1) {
// TODO Auto-generated method stub
}
public void onMapCenterChangeFine(NMapView arg0) {
// TODO Auto-generated method stub
}
});
mMapView.setOnMapViewTouchEventListener(new NMapView.OnMapViewTouchEventListener() {
public void onLongPress(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
}
public void onLongPressCanceled(NMapView arg0) {
// TODO Auto-generated method stub
}
public void onScroll(NMapView arg0, MotionEvent arg1, MotionEvent arg2) {
// TODO Auto-generated method stub
}
public void onSingleTapUp(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
}
public void onTouchDown(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
}
public void onTouchUp(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
}
});
}
public void onLongPress(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
}
public void onLongPressCanceled(NMapView arg0) {
// TODO Auto-generated method stub
}
public void onScroll(NMapView arg0, MotionEvent arg1, MotionEvent arg2) {
// TODO Auto-generated method stub
}
public void onSingleTapUp(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
}
public void onTouchDown(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
}
public void onTouchUp(NMapView arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
}
public void onAnimationStateChange(NMapView arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
public void onMapCenterChange(NMapView arg0, NGeoPoint arg1) {
// TODO Auto-generated method stub
}
public void onMapCenterChangeFine(NMapView arg0) {
// TODO Auto-generated method stub
}
public void onMapInitHandler(NMapView arg0, NMapError arg1) {
// TODO Auto-generated method stub
}
public void onZoomLevelChange(NMapView arg0, int arg1) {
// TODO Auto-generated method stub
}
private void checkDangerousermissions() {
String[] permssions = {
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.CHANGE_WIFI_STATE,
Manifest.permission.INTERNET,
};
int permissionCheck = PackageManager.PERMISSION_GRANTED;
for (int i = 0; i < permssions.length; i++) {
permissionCheck = ContextCompat.checkSelfPermission(this, permssions[i]);
if (permissionCheck == PackageManager.PERMISSION_DENIED) {
break;
}
}
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "그랜티드", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "그랜티드1", Toast.LENGTH_SHORT).show();
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permssions[0])) {
Toast.makeText(this, "그랜티드2", Toast.LENGTH_SHORT).show();
per=true;
} else {
ActivityCompat.requestPermissions(this, permssions, 1);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
for (int i = 0; i < permissions.length; i++) {
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, permissions[i] + "성공", Toast.LENGTH_SHORT).show();
per=true;
} else {
Toast.makeText(this, permissions[i] + "실패", Toast.LENGTH_SHORT).show();
}
}
}
}
private final NMapLocationManager.OnLocationChangeListener onMyLocationChangeListener = new NMapLocationManager.OnLocationChangeListener() {
@Override
public boolean onLocationChanged(NMapLocationManager locationManager,
NGeoPoint myLocation) {
// if (mMapController != null) {
// mMapController.animateTo(myLocation);
// }
Log.e("Test", "myLocation lat " + myLocation.getLatitude());
Log.e("Test", "myLocation lng " + myLocation.getLongitude());
findPlacemarkAtLocation(myLocation.getLongitude(), myLocation.getLatitude());
//위도경도를 주소로 변환
return true;
}
@Override
public void onLocationUpdateTimeout(NMapLocationManager locationManager) {
// stop location updating
// Runnable runnable = new Runnable() {
// public void run() {
// stopMyLocation();
// }
// };
// runnable.run();
}
@Override
public void onLocationUnavailableArea(
NMapLocationManager locationManager, NGeoPoint myLocation) {
}
};
@Override
public NMapCalloutOverlay onCreateCalloutOverlay(NMapOverlay nMapOverlay, NMapOverlayItem nMapOverlayItem, Rect rect) {
return null;
}
}
mMapView.setOnMapStateChangeListener(..) 를 두번 호출해서 두개의 리스너를 등록하는 이유가 있는지?
그리고 오버라이딩한 setMapDataProviderListener(...)는 누가 호출해주는지...? 저렇게 오버라이딩하는게 아니라, 리스너 구현체를 만들어서 상위 클래스에 있는 setMapDataProviderListener(...) 를 호출해주는거 아닌지?
리스너 OnDataProviderListener 의 구현체가 없는거같은데?