Git Product home page Git Product logo

Comments (5)

MosCriogen avatar MosCriogen commented on July 18, 2024 1

метод интеграции в моё приложение - по пунктам из описания. Делаем новый класс, в его конструкторе регистрируем интерфейс, и начинаем получать координаты координаты.

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.

Lezh1k avatar Lezh1k commented on July 18, 2024

Добрый день.
Вообще говоря там есть пример приложения. Более простой вариант постараюсь в ближайшие пару дней оформить в виде документа.
Но там вообще просто надо стартовать GPSKalmanService и подписаться на событие .

from mad-location-manager.

dgaenko avatar dgaenko commented on July 18, 2024

было просто шикарно. Заранее спасибо!

from mad-location-manager.

dgaenko avatar dgaenko commented on July 18, 2024

from mad-location-manager.

Lezh1k avatar Lezh1k commented on July 18, 2024

Похоже вопрос решен.

from mad-location-manager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.