2013-04-17 2 views
0

내 응용 프로그램에서 LocationManager의 속도를 높이고 싶습니다. setSpeedRequired (true) 특성을 가진 기준이 있습니다. 나는 location.getSPeed()를하고 있지만 항상 0을 제공합니다. 아래는 내가 서비스로 실행하고있는 GPS 코드입니다.안드로이드 GPS에서 속도 받기

public class Tracking extends Service implements LocationListener { 

    protected LocationManager locationManager; 
    Location location; 
    double latitude; 
    double longitude; 
    float velocity; 
    String provider; 

    private static final long minDist = 0; 
    private static final long minTime = 0; 
    LocationDatabaseHandler ldb; 


    @Override 
    public void onCreate() { 
     ldb = new LocationDatabaseHandler(this); 
     getLocation(); 
    } 

    @Override 
    public void onDestroy() { 
     super.onDestroy(); 
    } 

    @Override 
    public void onProviderDisabled(String provider) { 

    } 

    @Override 
    public void onProviderEnabled(String provider) { 

    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) { 

    } 

    @Override 
    public IBinder onBind(Intent intent) { 
     return null; 
    } 

    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) { 
     super.onStartCommand(intent,flags,startId); 
     //because we do not want to stop the service unless we explicitly say so. 
     return START_STICKY; 
    } 

    public Location getLocation() { 
     locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     Criteria criteria = new Criteria(); 
     criteria.setSpeedRequired(true); 
     provider = locationManager.getBestProvider(criteria, false); 

     locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDist, 
       this); 
     location = locationManager.getLastKnownLocation(provider); 
     if(location != null) { 
      onLocationChanged(location);    
     } 

     return location;   
    } 

    @Override 
    public void onLocationChanged(Location location) { 
     latitude = location.getLatitude(); 
     longitude = location.getLongitude(); 
     batteryP = getBatteryPerc(); 
     velocity = location.getSpeed(); 

     insertIntoDb(latitude, longitude, velocity, "onchanged"); 
    } 

    public void insertIntoDb(double latitude, double longitude, float velocity, String where) { 
     Date date = new Date(); 
     String dateStr = date.toString(); 

     ldb.addLocation(new Locations(latitude, longitude, dateStr, velocity)); 
    } 

} 

데이터베이스를 볼 때 속도는 항상 0.0입니다. 제가 누락 된 것이 있습니까?

+0

'getSpeed ​​()'코드가 나에게 잘 보인다. GPS 잠금 장치가 있다고 확신합니까? 'getSpeed ​​()'는 반환 할 수있는 속도가없는 경우 항상 0을 반환합니다. –

+0

'location.getAccuracy()'의 값을 확인하고 볼 수 있습니다. GpsStatus.Listener를 사용하여 GPS 상태 (GPS 잠금 장치가있는 경우 연결되어있는 위성의 수 등)를 확인할 수도 있습니다. –

+0

여기에 대한 자세한 정보는 여기를 참조하십시오. 'm 이야기에 대해 http://stackoverflow.com/questions/2021176/how-can-i-check-the-current-status-of-the-gps-receiver/3712727#3712727 이것은 내가 처음에 자동차를 썼을 때 매우 도움이되었습니다. 계기반 –

답변

-2

locationManager.requestLocationUpdates (provider, minTime, minDist, this);

관련 문제