Comments (5)
метод интеграции в моё приложение - по пунктам из описания. Делаем новый класс, в его конструкторе регистрируем интерфейс, и начинаем получать координаты координаты.
import android.content.Context;
import android.location.Location;
import mad.location.manager.lib.Commons.Utils;
import mad.location.manager.lib.Interfaces.LocationServiceInterface;
import mad.location.manager.lib.Services.KalmanLocationService;
import mad.location.manager.lib.Services.ServicesHelper;
public class Kalman implements LocationServiceInterface {
private Context m_context;
private Context m_appp_context;
private CGeohashRTFilter m_geoHashRTFilter;
private KalmanLocationService.Settings settings;
public Kalman (Context app_context, Context context) {
m_context = context;
m_appp_context = app_context;
m_geoHashRTFilter = new CGeohashRTFilter( m_appp_context, 8, 2);
settings = new KalmanLocationService.Settings(Utils.ACCELEROMETER_DEFAULT_DEVIATION,
Utils.GPS_MIN_DISTANCE,
Utils.GPS_MIN_TIME,
Utils.GEOHASH_DEFAULT_PREC,
Utils.GEOHASH_DEFAULT_MIN_POINT_COUNT,
Utils.SENSOR_DEFAULT_FREQ_HZ,
null, false, Utils.DEFAULT_VEL_FACTOR, Utils.DEFAULT_POS_FACTOR);
ServicesHelper.addLocationServiceInterface(this);
}
public void start_k () {
ServicesHelper.getLocationService(m_context, value -> {
if (value.IsRunning()) {
return;
}
value.stop();
value.reset(settings); //warning!! here you can adjust your filter behavior
m_geoHashRTFilter.reset();
value.start();
});
}
public void stop_k () {
ServicesHelper.getLocationService(m_context, value -> {
value.stop();
});
m_geoHashRTFilter.stop();
}
@Override
public void locationChanged(Location location) {
m_geoHashRTFilter.filter( location );
}
}
В основном приложении, например в main () делаем экземпляр класса
...
...
...
private Kalman kalman;
kalman = new Kalman( getApplicationContext(), this );
kalman.start_k();
В конкретно моём случае координаты должны сохраняться в базу данных. Для этого я скопировал из библиотеки класс GeoHashRTFilter и переделал его так чтоб его результат сохранялся не во внутренний список, а в базу данных:
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.location.Location;
import com.orderssupportapp.database.dbContract;
import com.orderssupportapp.database.dbHelper;
import java.text.SimpleDateFormat;
import java.util.Date;
import mad.location.manager.lib.Filters.GeoHash;
public class CGeohashRTFilter {
private static final double COORD_NOT_INITIALIZED = 361.0;
private int ppCompGeoHash = 0;
private int ppReadGeoHash = 1;
private long geoHashBuffers[];
private int pointsInCurrentGeohashCount;
private CGeoPoint currentGeoPoint;
private boolean isFirstCoordinate = true;
private int m_geohashPrecision;
private int m_geohashMinPointCount;
private dbHelper mDbHelper;
private SQLiteDatabase db;
private SimpleDateFormat dateFormat;
public CGeohashRTFilter(Context context, int geohashPrecision, int geohashMinPointCount) {
m_geohashPrecision = geohashPrecision;
m_geohashMinPointCount = geohashMinPointCount;
mDbHelper = new dbHelper( context );
db = mDbHelper.getWritableDatabase();
dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); //"dd.MM.yyyy HH:mm:ss");
reset();
}
public void reset() {
geoHashBuffers = new long[2];
pointsInCurrentGeohashCount = 0;
currentGeoPoint = new CGeoPoint(COORD_NOT_INITIALIZED, COORD_NOT_INITIALIZED, 0);
isFirstCoordinate = true;
}
public void filter(Location loc) {
CGeoPoint pi = new CGeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getSpeed());
if (isFirstCoordinate) {
geoHashBuffers[ppCompGeoHash] = GeoHash.encode_u64(pi.Latitude, pi.Longitude, m_geohashPrecision);
currentGeoPoint.Latitude = pi.Latitude;
currentGeoPoint.Longitude = pi.Longitude;
currentGeoPoint.Velocity = pi.Velocity;
pointsInCurrentGeohashCount = 1;
isFirstCoordinate = false;
return;
}
geoHashBuffers[ppReadGeoHash] = GeoHash.encode_u64(pi.Latitude, pi.Longitude, m_geohashPrecision);
if (geoHashBuffers[ppCompGeoHash] != geoHashBuffers[ppReadGeoHash]) {
if (pointsInCurrentGeohashCount >= m_geohashMinPointCount) {
ContentValues values = new ContentValues();
values.put( dbContract.gpsEntry.COLUMN_USED, 0 );
values.put( dbContract.gpsEntry.COLUMN_DATE, dateFormat.format(loc.getTime()).toString() );
values.put( dbContract.gpsEntry.COLUMN_LATITUDE, currentGeoPoint.Latitude/pointsInCurrentGeohashCount );
values.put( dbContract.gpsEntry.COLUMN_LONGITUDE, currentGeoPoint.Longitude/pointsInCurrentGeohashCount );
values.put( dbContract.gpsEntry.COLUMN_VELOCITY, currentGeoPoint.Velocity/pointsInCurrentGeohashCount );
long newRowId = db.insert( dbContract.gpsEntry.TABLE_NAME, null, values );
}
pointsInCurrentGeohashCount = 1;
currentGeoPoint.Latitude = pi.Latitude;
currentGeoPoint.Longitude = pi.Longitude;
currentGeoPoint.Velocity = pi.Velocity;
//swap buffers
int swp = ppCompGeoHash;
ppCompGeoHash = ppReadGeoHash;
ppReadGeoHash = swp;
return;
}
currentGeoPoint.Latitude += pi.Latitude;
currentGeoPoint.Longitude += pi.Longitude;
currentGeoPoint.Velocity += pi.Velocity;
++pointsInCurrentGeohashCount;
}
public void stop() {
if (pointsInCurrentGeohashCount >= m_geohashMinPointCount) {
ContentValues values = new ContentValues();
values.put( dbContract.gpsEntry.COLUMN_USED, 0 );
values.put( dbContract.gpsEntry.COLUMN_DATE, dateFormat.format(new Date()).toString() );
values.put( dbContract.gpsEntry.COLUMN_LATITUDE, currentGeoPoint.Latitude/pointsInCurrentGeohashCount );
values.put( dbContract.gpsEntry.COLUMN_LONGITUDE, currentGeoPoint.Longitude/pointsInCurrentGeohashCount );
values.put( dbContract.gpsEntry.COLUMN_VELOCITY, currentGeoPoint.Velocity/pointsInCurrentGeohashCount );
long newRowId = db.insert( dbContract.gpsEntry.TABLE_NAME, null, values );
currentGeoPoint.Velocity = 0;
currentGeoPoint.Latitude = currentGeoPoint.Longitude = 0.0;
}
}
}
И чтоб кроме координат в базу данных сохранялась скорость в точке, сделал свою версию класса GeoPoint
public class CGeoPoint {
public double Latitude;
public double Longitude;
public float Velocity;
public CGeoPoint(double latitude, double longitude, float velocity) {
Latitude = latitude;
Longitude = longitude;
Velocity = velocity;
}
}
from mad-location-manager.
Добрый день.
Вообще говоря там есть пример приложения. Более простой вариант постараюсь в ближайшие пару дней оформить в виде документа.
Но там вообще просто надо стартовать GPSKalmanService и подписаться на событие .
from mad-location-manager.
было просто шикарно. Заранее спасибо!
from mad-location-manager.
from mad-location-manager.
Похоже вопрос решен.
from mad-location-manager.
Related Issues (20)
- how to calculate predicted estimate covariance matrix in gpsacckalmanfilter ?? HOT 1
- KalmanLocationService crashing HOT 7
- Location filtering with FusedLocationProvider HOT 5
- for gps accuracy
- Sensor calibration needed ? HOT 3
- gpsacckalmanfilter tutorial video ? HOT 1
- Demo App crashes with GPS Provider
- URGENT HELP HOT 5
- crash with deprecated api GPSStatus in "onStop()" method GPSLocationProvider file
- Maven Plugin doesn't work with Gradle 7.2 on Android Studio
- Doesn't work with Gradle 7.1.3
- Demo app crash
- Android location manager does not handle sensors ? HOT 1
- Фильтр Калмана не работает ожидаемым образом HOT 3
- questions on some logic used in code HOT 1
- Need help for starting demo app HOT 2
- Old device without sensors TYPE_ROTATION_VECTOR, TYPE_LINEAR_ACCELERATION HOT 4
- GPSAccKalmanFilter HOT 2
- Trouble updating mapbox sdk version HOT 1
- Kalman location service started location random coords HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mad-location-manager.