2014-09-05 132 views
0

我試圖在谷歌玻璃活卡上顯示用戶的速度。 我能夠獲得經度和緯度,但getSpeed()總是返回0.0。我已經檢查過類似的問題,但沒有幫助。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.您只能從調用setSpeed提供商getSpeed。您可以設置標準變量來表明您需要速度值。

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

或者您可能會考慮自己計算一下。見why getSpeed() always return 0 on android

此外,使用hasSpeed()來檢查速度是否可用。

+0

即使我設置標準..速度返回0 ..任何線索? – 2014-10-30 11:05:46

+1

好吧,我不確定。可能是GDK的錯誤。它仍然是測試版,請耐心等待。 – pt2121 2014-10-31 03:08:34