2011-04-11 3 views
1

requestLocatioupdate 메소드에서 minTime을 10 초로 설정했지만 1 초 이내에 새 위치를 얻습니다.안드로이드 GPS 제공 업체의 문제점 : 너무 많은 업데이트

public class GpsActivity extends Activity { 
LocationManager mLocationManager; 
TextView mTextView; 
int count; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     mTextView = (TextView) findViewById(R.id.text); 
     count = 0; 
     mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
     mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0,mGpsLocationListener); 
    } 

    Handler mHandler = new Handler(){ 

     @Override 
     public void handleMessage(Message msg){ 
      switch(msg.what){ 
      case 1: 
       mTextView.setText("new location count:"+count); 
      } 
     } 
    }; 

    LocationListener mGpsLocationListener = new LocationListener(){ 

    @Override 
    public void onLocationChanged(Location location) { 
     count++; 
     mHandler.sendEmptyMessage(1); 

    } 

    @Override 
    public void onProviderDisabled(String arg0) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onProviderEnabled(String arg0) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onStatusChanged(String arg0, int arg1, Bundle arg2) { 
     // TODO Auto-generated method stub 

    } 

    }; 

} 

내 프로그램은 안드로이드 2.2

모든 아이디어를 위해 작성되었습니다?

미리 감사드립니다.

답변

0

거리를 설정할 수 있습니다. 해결되지 않으면 다음을 참조하십시오. minTime 알림의 최소 시간 간격 (밀리 초). 이 필드는 전원을 절약하기위한 힌트로만 사용되며 위치 업데이트 간의 실제 시간은이 값보다 크거나 작을 수 있습니다. minDistance 알림을위한 최소 거리 간격 (단위 : 미터)

업데이트 10 초를 희망한다면 시간이 정확하지 않다고 생각합니다. 시간 andTimeTask 또는 처리기를 사용해야한다고 생각합니다. 또는보실 수 있습니다 http://androidforums.com/developer-101/107085-proper-provider-parameter-requestlocationupdates.html

+0

도움 주셔서 대단히 감사합니다. – mnish