2014-09-05 3 views
0

Я пытаюсь отобразить скорость пользователя на живой карточке Google. Я могу получить широту и долготу, но getSpeed ​​() всегда возвращает 0.0. Я проверил подобные вопросы по SO, но без помощи.Google glass-GDK app getSpeed ​​() возвращает 0.0

Вот мой код

 Criteria criteria = new Criteria(); 
     criteria.setAccuracy(Criteria.ACCURACY_FINE); 
     LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
     String provider = mLocationManager.getBestProvider(criteria, true); 
     boolean isEnabled = mLocationManager.isProviderEnabled(provider); 
     if (isEnabled) { 
     // Define a listener that responds to location updates 
     LocationListener locationListener = new LocationListener() { 
     @Override 
     public void onLocationChanged(Location location) { 
     // Called when a new location is found by the network location provider. 
     if (location != null) { 
     Geocoder geocoder = new Geocoder(Start_service.this.getBaseContext(), Locale.getDefault()); 
     // lat,lng, your current location 
     List<Address> addresses = null; 
     try { 
      lati= location.getLatitude(); 
      longi=location.getLongitude(); 
      speed=location.getSpeed(); 
     addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); 
     } 
     catch (IOException e) { 
     System.out.println(e); 
     e.printStackTrace(); 
     } 

ответ

1

Location providers don't guarantee to provide the speed value. Вы можете только getSpeed ​​от поставщика, который вызывает SetSpeed. Вы можете установить переменную Criteria, чтобы указать, что вам нужно значение скорости.

Criteria criteria = new Criteria(); 
criteria.setSpeedRequired(true); 

Или вы можете подумать рассчитать его самостоятельно. См. why getSpeed() always return 0 on android.

Кроме того, используйте hasSpeed ​​(), чтобы проверить, доступна ли скорость.

+0

Даже если я задал критерии .. скорость возвращается 0..Любые подсказки? –

+1

ну, я не уверен. вероятно, ошибка GDK. Это все еще бета, поэтому, пожалуйста, будьте терпеливы. – pt2121

Смежные вопросы