Google Map View를 만들어서 현재위치 실시간으로 잘 갱신해서 쓰다가 removeupdate를 사용하지 않으면 계속

 

로케이션을 업데이트하는것 같아서 다른 액티비티에서 이 실시간 갱신값을 캐치해서 사용할 수 있을까 합니다

 

그런데 이렇게 값을 받아오려고 하니

 

java.lang.illegalstateexception: System services not available to Activities before onCreate()

 

문제가 생기네요 ㅠㅠ  빨간색 부분에서 문제가 생깁니다

 

해결방법좀 알려주시면 감사하겠습니다 ㅠㅠ

 

아니면 그냥 각각의 액티비티에서 다 따로 location manager를 만들어 써야할까요...??

 

public class LocationActivity extends MapActivity implements OnClickListener{
 protected MapView mapView;
 protected MapController mapCtrl;
 protected Button Myloc;
 protected Button Targetloc;
 protected Button ArgumentedReality;
 protected GeoPoint TargetGeopoint;
 protected GeoPoint UserGeopoint;
 protected LocationManager LocManager;
 protected LocationListener LocListener;
 protected int UserGeoX;
 protected int UserGeoY;
 protected int UserGpsGeoX;
 protected int UserGpsGeoY;
 protected int UserNetGeoX;
 protected int UserNetGeoY;
 protected int TargetGeoX;
 protected int TargetGeoY;
 protected boolean CurrentLocAnimateEnable;
 protected boolean _Wifi_Enable;
 protected boolean _3G_Enable;
 protected EditText GPText;
 protected String TargetName;
 protected Location GPSloc;
 protected Location Networkloc;protected int[] updateState() {
LocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, (long)10000, (float)10, LocListener);
LocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, (long)10000, (float)10, LocListener);
CheckNetworkStatus();
Toast.makeText(LocationActivity.this, "Current Location Changed", Toast.LENGTH_SHORT).show();
GPSloc = LocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Networkloc = LocManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
// Positioning Accuracy : wifi > GPS > 3G
/*/
if(_Wifi_Enable) {
UserNetGeoX = (int)(1000000*Networkloc.getLatitude());
UserNetGeoY = (int)(1000000*Networkloc.getLongitude());
UserGeoX = UserNetGeoX;
UserGeoY = UserNetGeoY;
}
else
//*/
if(GPSloc!=null){
UserGpsGeoX = (int)(1000000*GPSloc.getLatitude());
UserGpsGeoY = (int)(1000000*GPSloc.getLongitude());
UserGeoX = UserGpsGeoX;
UserGeoY = UserGpsGeoY;
}
else if(Networkloc!=null) {
UserNetGeoX = (int)(1000000*Networkloc.getLatitude());
UserNetGeoY = (int)(1000000*Networkloc.getLongitude());
UserGeoX = UserNetGeoX;
UserGeoY = UserNetGeoY;
}
else {
Log.d("location", "location is null");
UserGeoX = 0;
UserGeoY = 0;
}
int[] UserGPIn = {UserGeoX,UserGeoY};
return UserGPIn;
}
private void updateDisplay(){
int[] UserGPIn = {UserGeoX,UserGeoY};
UserGeopoint = new GeoPoint(UserGeoX,UserGeoY);
//Enable List
mapView.getOverlays().set(1, new Markers(UserGPIn,"현재위치"+"Wifi:"+_Wifi_Enable+"3G:"+_3G_Enable,this));

if(GPSloc==null) GPText.setText("NetGP : "+UserNetGeoX+","+UserNetGeoY+"\nGpsGP is not availiable");
else GPText.setText("NetGP : "+UserNetGeoX+","+UserNetGeoY+"\nGpsGP : "+UserGpsGeoX+","+UserGpsGeoY);
if(CurrentLocAnimateEnable==true) mapCtrl.animateTo(UserGeopoint);
else GPText.setText("Geopoint of "+TargetName+" : "+TargetGeoX+","+TargetGeoY);
}

protected boolean[] CheckNetworkStatus(){
final ConnectivityManager connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (wifi.isAvailable()) { _Wifi_Enable = true; _3G_Enable = false; }
else if (mobile.isAvailable()) { _Wifi_Enable = false; _3G_Enable = true; }
else { _Wifi_Enable = false; _3G_Enable = false; }
boolean[] Wifi_3G = {_Wifi_Enable,_3G_Enable};
return Wifi_3G;

 protected int[] updateState() {
  LocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, (long)10000, (float)10, LocListener);
        LocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, (long)10000, (float)10, LocListener);
  CheckNetworkStatus();
  Toast.makeText(LocationActivity.this, "Current Location Changed", Toast.LENGTH_SHORT).show();
  GPSloc = LocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        Networkloc = LocManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        // Positioning Accuracy : wifi > GPS > 3G
  /*/
  if(_Wifi_Enable) {
   UserNetGeoX = (int)(1000000*Networkloc.getLatitude());
   UserNetGeoY = (int)(1000000*Networkloc.getLongitude());
   UserGeoX = UserNetGeoX;
   UserGeoY = UserNetGeoY;
  }
  else
  //*/
  if(GPSloc!=null){
   UserGpsGeoX = (int)(1000000*GPSloc.getLatitude());
   UserGpsGeoY = (int)(1000000*GPSloc.getLongitude());
   UserGeoX = UserGpsGeoX;
   UserGeoY = UserGpsGeoY;
  }
  else if(Networkloc!=null) {
   UserNetGeoX = (int)(1000000*Networkloc.getLatitude());
   UserNetGeoY = (int)(1000000*Networkloc.getLongitude());
   UserGeoX = UserNetGeoX;
   UserGeoY = UserNetGeoY;          
  }
  else {
   Log.d("location", "location is null");
         UserGeoX = 0;
         UserGeoY = 0;
  }
  int[] UserGPIn = {UserGeoX,UserGeoY};
  return UserGPIn;
 }
 private void updateDisplay(){
  int[] UserGPIn = {UserGeoX,UserGeoY};
  UserGeopoint = new GeoPoint(UserGeoX,UserGeoY);
//Enable List
  mapView.getOverlays().set(1, new Markers(UserGPIn,"현재위치"+"Wifi:"+_Wifi_Enable+"3G:"+_3G_Enable,this));
  
  if(GPSloc==null) GPText.setText("NetGP : "+UserNetGeoX+","+UserNetGeoY+"\nGpsGP is not availiable");
  else GPText.setText("NetGP : "+UserNetGeoX+","+UserNetGeoY+"\nGpsGP : "+UserGpsGeoX+","+UserGpsGeoY);
  if(CurrentLocAnimateEnable==true) mapCtrl.animateTo(UserGeopoint);
  else GPText.setText("Geopoint of "+TargetName+" : "+TargetGeoX+","+TargetGeoY);
 }
 
 protected boolean[] CheckNetworkStatus(){
  final ConnectivityManager connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
  final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
  final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
  if (wifi.isAvailable()) { _Wifi_Enable = true; _3G_Enable = false; }
  else if (mobile.isAvailable()) { _Wifi_Enable = false; _3G_Enable = true; }
  else { _Wifi_Enable = false; _3G_Enable = false; }
  boolean[] Wifi_3G = {_Wifi_Enable,_3G_Enable};
  return Wifi_3G;
 }


public class LocationUpdater extends LocationActivity{
 protected Location GPSloc = super.GPSloc;
 protected Location Networkloc = super.Networkloc;
 public boolean[] CheckNetworkStatus(){
  boolean[] NetworkStatus = super.CheckNetworkStatus();
  return NetworkStatus;
 }
 
 private int[] GetCurrentUserGP(){
  int[] CurrentUserGP = super.updateState();
  return CurrentUserGP;
 }
}

    LocationUpdater LocUpdater = new LocationUpdater(this);
    Location GPSloc = LocUpdater.GPSloc;
    Location Networkloc = LocUpdater.Networkloc;

private final SensorEventListener mListener = new SensorEventListener() {
        public void onSensorChanged(SensorEvent event) {
            Log.i(TAG,"sensorChanged ("+event.values[0]+", "+event.values[1]+", "+event.values[2]+")");
            mValues = event.values;
            //Get Compass Azimuth
            if(Renewal_Counter>10){
             UserLatitude = LocUpdater.updateState()[0];
          UserLongitude = LocUpdater.updateState()[1];
          Angle = azimuth.GetAngleInDegrees(UserLongitude, UserLatitude, TargetLongitude, TargetLatitude);//GPS Azimuth
          Renewal_Counter=0;//Renewal_Counter ++;는 onDraw쪽에 만들어서 이상없이 잘 올라갑니다
          //Toast.makeText(Camera_ComActivity.this, "Location Update Succeed!!", Toast.LENGTH_LONG).show();
            }
            if ((mValues[0]>=0)&&(mValues[0]<=270)) CompassAzimuth = mValues[0]+90;
            else CompassAzimuth = mValues[0]-270;
             
            if (way != null) {
                way.invalidate();
            }
            CompassTestAzimuth = mValues[0];
            CompassPitch = mValues[1];
            CompassRoll = mValues[2];
        }
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
        }
    };


 


어떤 의견이라도 귀귀울여듣겠습니다!!!

 

도움부탁드릴게요 ㅠㅠ!!