Tag: android gps

固定间隔后获取纬度位置

对于速度测量应用程序,我需要在每四秒后获得经度和经度更新。 我在两次调用getLatitude和getLongitude函数之间使用了sleep函数。 但是在屏幕上打印显示值保持不变,即lon1和lon2,因为双精度数(十进制后的14位)具有完全相同的值,因此速度也显示为0。 如何在固定的时间间隔(此处为4秒)后获得纬度和经度? 非常感谢提前。 locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { double r = 6371; double lat1 = location.getLatitude(); double lon1 = location.getLongitude(); // To get initial longitude SystemClock.sleep(4000); /////This seems ineffective. double lat2 = location.getLatitude(); double lon2 = location.getLongitude(); // and here double dlat = […]