【问题标题】:Google glass- GDK app getSpeed() returns 0.0Google glass-GDK 应用程序 getSpeed() 返回 0.0
【发布时间】:2014-09-05 09:09:13
【问题描述】:

我正在尝试在 google glass live card 上显示用户的速度。 我能够得到纬度和经度,但 getSpeed() 总是返回 0.0。我已经检查了关于 SO 的类似问题,但没有任何帮助。

这是我的代码

        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();
        }

【问题讨论】:

    标签: android gps google-glass google-gdk


    【解决方案1】:

    Location providers don't guarantee to provide the speed value. 你只能从调用 setSpeed 的提供者那里得到速度。您可以设置 Criteria 变量来指示您需要速度值。

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

    或者您可以考虑自己计算。见why getSpeed() always return 0 on android

    另外,使用 hasSpeed() 检查速度是否可用。

    【讨论】:

    • 即使我设置了标准..速度返回0..任何线索?
    • 好吧,我不确定。可能是GDK的错误。它仍然是测试版,所以请耐心等待。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-28
    • 1970-01-01
    相关资源
    最近更新 更多