안드로이드 개발 질문/답변
(글 수 45,052)
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
// load GPS( GPS 로 부터 현재의 내 위치 가져오기 )
loadGps();// location 값할당
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable,this);
GeoPoint point = new GeoPoint((int)(37.5643406*1E6),(int)(126.9756087*1E6));
double latPoint = location.getLatitude();
Log.i("aa", ""+latPoint);
double lngPoint = location.getLongitude();
Log.i("bb", ""+lngPoint);
//GeoPoint point = new GeoPoint((int) (location.getLatitude() * 1E6),(int) (location.getLongitude() * 1E6));
OverlayItem overlayitem = new OverlayItem(point, "Hi Pondol!","I'm in Seoul!");
itemizedoverlay.addOverlay(overlayitem);
mapController = mapView.getController();
mapController.setCenter(point);
mapController.setZoom(15); //
mapController.animateTo(point);
mapOverlays.add(itemizedoverlay);
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
public void loadGps() {
Log.w(TAG, "loadGps Start");
String context = Context.LOCATION_SERVICE;// 안드로이드 시스템으로 부터
// LocationManager 서비스를 요청하여
// 할당
locationManager = (LocationManager) getSystemService(context);
// GPS 환경설정
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE); // 정확도
criteria.setPowerRequirement(Criteria.POWER_LOW); // 전원 소비량
criteria.setAltitudeRequired(false); // 고도, 높이 값을 얻어 올지를 결정
criteria.setBearingRequired(false); // provider 기본 정보
criteria.setSpeedRequired(false); // 속도
criteria.setCostAllowed(true); // 위치 정보를 얻어 오는데 들어가는 금전적 비용
// 상기 조건을 이용하여 알맞은 GPS선택후 위치정보를 획득
// manifest xml : <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
// 로케이션 메니저의 provider
provider = locationManager.getBestProvider(criteria, true);
Log.i(TAG, "provider:" + provider);
if (provider == null) {// GPS 장치가 없는 휴대폰이거나 설정이 꺼져있는 경우 바로 alert 처리하거나
// GPS 설정으로 이동
result = chkGpsService();
if (result) {
loadGps();
}
} else {
location = locationManager.getLastKnownLocation(provider);// 가장 최근의 로케이션을 가져온다.
// 안드로이드 폰이 꺼져있었거나 다른 위치로 이동한 경우 값이 없다.
// location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
// 이럴경우는 NETWORK_PROVIDER 로 부터 새로운 location을 지정 받는다.
// 특정조건(시간, 거리)이 되면 Listener를 invoke 시킨다.: 여기서는 1초 마다 5km)
locationManager.requestLocationUpdates(provider, 1000, 5, loclistener);// 현재정보를 업데이트
if (location == null) {
location = locationManager.getLastKnownLocation(provider);
if (location == null) {// 그래도 null인경우 alert;
Log.w(TAG, "get Location From GPS Fail !!!!!");
}
}
}
}
빨간 부분에서 에러가 납니다..ㅠㅠ
위도와 경도를 다시 한번 따루따루 가져오려고하는데..
에러나 납니다..nullpoint라면서요...
따루따루 가져오려면 어떻게해야할까여~
답변부탁드립니다




NullPointerException은 말 그대로 Null일때 나는 에러 입니다만...
Gps면 GPS가 켜져 있는지부터 확인해 보세요.