Add approximated localizations
This commit is contained in:
parent
98cc5bcc20
commit
64b24cef1b
@ -58,7 +58,7 @@ dependencies {
|
||||
implementation 'com.auth0.android:jwtdecode:1.1.1'
|
||||
implementation 'com.annimon:stream:1.2.1'
|
||||
implementation 'com.google.android.gms:play-services-location:16.0.0'
|
||||
|
||||
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:4.0.0'
|
||||
// FloatingBarMenu
|
||||
implementation 'com.getbase:floatingactionbutton:1.10.1'
|
||||
|
||||
|
386
app/src/main/assets/building.geojson
Normal file
386
app/src/main/assets/building.geojson
Normal file
@ -0,0 +1,386 @@
|
||||
{
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Skrzydło B"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.92618,
|
||||
52.466248
|
||||
],
|
||||
[
|
||||
16.926435,
|
||||
52.466201
|
||||
],
|
||||
[
|
||||
16.92646,
|
||||
52.466255
|
||||
],
|
||||
[
|
||||
16.926516,
|
||||
52.466244
|
||||
],
|
||||
[
|
||||
16.926999,
|
||||
52.46711
|
||||
],
|
||||
[
|
||||
16.926796,
|
||||
52.467145
|
||||
],
|
||||
[
|
||||
16.926782,
|
||||
52.467117
|
||||
],
|
||||
[
|
||||
16.926784,
|
||||
52.467121
|
||||
],
|
||||
[
|
||||
16.926691,
|
||||
52.467139
|
||||
],
|
||||
[
|
||||
16.926662,
|
||||
52.46709
|
||||
],
|
||||
[
|
||||
16.926757,
|
||||
52.467072
|
||||
],
|
||||
[
|
||||
16.926544,
|
||||
52.466691
|
||||
],
|
||||
[
|
||||
16.926434,
|
||||
52.46671
|
||||
],
|
||||
[
|
||||
16.926396,
|
||||
52.466655
|
||||
],
|
||||
[
|
||||
16.926519,
|
||||
52.466628
|
||||
],
|
||||
[
|
||||
16.926323,
|
||||
52.466281
|
||||
],
|
||||
[
|
||||
16.926213,
|
||||
52.466307
|
||||
],
|
||||
[
|
||||
16.92618,
|
||||
52.466248
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "41798cf663bc55c10e6c51c3fe174eda"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Biblioteka"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.927048,
|
||||
52.46721
|
||||
],
|
||||
[
|
||||
16.926627,
|
||||
52.467295
|
||||
],
|
||||
[
|
||||
16.926732,
|
||||
52.467482
|
||||
],
|
||||
[
|
||||
16.926876,
|
||||
52.467461
|
||||
],
|
||||
[
|
||||
16.926967,
|
||||
52.467428
|
||||
],
|
||||
[
|
||||
16.927014,
|
||||
52.467402
|
||||
],
|
||||
[
|
||||
16.927171,
|
||||
52.467359
|
||||
],
|
||||
[
|
||||
16.9271,
|
||||
52.467202
|
||||
],
|
||||
[
|
||||
16.927048,
|
||||
52.46721
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "7328c3c9dffd3e76be8d3dcef4f58ddc"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Łącznik"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926759,
|
||||
52.466683
|
||||
],
|
||||
[
|
||||
16.927088,
|
||||
52.46661
|
||||
],
|
||||
[
|
||||
16.927019,
|
||||
52.466502
|
||||
],
|
||||
[
|
||||
16.9267,
|
||||
52.466571
|
||||
],
|
||||
[
|
||||
16.926759,
|
||||
52.466683
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "8c19ee28e4c07ece9756fd21f290713b"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Skrzydło A"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926771,
|
||||
52.466106
|
||||
],
|
||||
[
|
||||
16.926898,
|
||||
52.466079
|
||||
],
|
||||
[
|
||||
16.926926,
|
||||
52.466126
|
||||
],
|
||||
[
|
||||
16.927026,
|
||||
52.466107
|
||||
],
|
||||
[
|
||||
16.92723,
|
||||
52.466473
|
||||
],
|
||||
[
|
||||
16.927184,
|
||||
52.466483
|
||||
],
|
||||
[
|
||||
16.927243,
|
||||
52.466586
|
||||
],
|
||||
[
|
||||
16.927334,
|
||||
52.46656
|
||||
],
|
||||
[
|
||||
16.927602,
|
||||
52.466889
|
||||
],
|
||||
[
|
||||
16.927275,
|
||||
52.466959
|
||||
],
|
||||
[
|
||||
16.926771,
|
||||
52.466106
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "c33bfba772c85cc38ae417843d31b1ff"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Aule"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.92731,
|
||||
52.467158
|
||||
],
|
||||
[
|
||||
16.927315,
|
||||
52.46718
|
||||
],
|
||||
[
|
||||
16.927348,
|
||||
52.467199
|
||||
],
|
||||
[
|
||||
16.927393,
|
||||
52.467224
|
||||
],
|
||||
[
|
||||
16.927426,
|
||||
52.467239
|
||||
],
|
||||
[
|
||||
16.927476,
|
||||
52.467258
|
||||
],
|
||||
[
|
||||
16.92755,
|
||||
52.467264
|
||||
],
|
||||
[
|
||||
16.927625,
|
||||
52.467263
|
||||
],
|
||||
[
|
||||
16.927699,
|
||||
52.467246
|
||||
],
|
||||
[
|
||||
16.92776,
|
||||
52.467212
|
||||
],
|
||||
[
|
||||
16.927821,
|
||||
52.467158
|
||||
],
|
||||
[
|
||||
16.927838,
|
||||
52.467099
|
||||
],
|
||||
[
|
||||
16.927827,
|
||||
52.467059
|
||||
],
|
||||
[
|
||||
16.927793,
|
||||
52.467012
|
||||
],
|
||||
[
|
||||
16.927738,
|
||||
52.466976
|
||||
],
|
||||
[
|
||||
16.927661,
|
||||
52.466949
|
||||
],
|
||||
[
|
||||
16.927581,
|
||||
52.466939
|
||||
],
|
||||
[
|
||||
16.927534,
|
||||
52.466938
|
||||
],
|
||||
[
|
||||
16.927467,
|
||||
52.466949
|
||||
],
|
||||
[
|
||||
16.927387,
|
||||
52.467047
|
||||
],
|
||||
[
|
||||
16.927315,
|
||||
52.467153
|
||||
],
|
||||
[
|
||||
16.92731,
|
||||
52.467158
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "c779419e3fd7faef8555e1099547a82c"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Hol",
|
||||
"point" : [52.467088, 16.927150]
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926625,
|
||||
52.467294
|
||||
],
|
||||
[
|
||||
16.926568,
|
||||
52.46719
|
||||
],
|
||||
[
|
||||
16.927008,
|
||||
52.467108
|
||||
],
|
||||
[
|
||||
16.926953,
|
||||
52.467024
|
||||
],
|
||||
[
|
||||
16.927463,
|
||||
52.466919
|
||||
],
|
||||
[
|
||||
16.927467,
|
||||
52.466956
|
||||
],
|
||||
[
|
||||
16.927316,
|
||||
52.467153
|
||||
],
|
||||
[
|
||||
16.926907,
|
||||
52.467235
|
||||
],
|
||||
[
|
||||
16.926625,
|
||||
52.467294
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "facdd5349991758b9ad99d4e123c91cc"
|
||||
}
|
||||
],
|
||||
"type": "FeatureCollection"
|
||||
}
|
@ -235,6 +235,7 @@ public class MapActivity extends BaseActivity
|
||||
latLng.getLatitude(),
|
||||
latLng.getLongitude(),
|
||||
latLng.getAltitude(),
|
||||
"approx",
|
||||
PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
PrefUtils.getLocationLevel(getApplicationContext())
|
||||
|
@ -44,7 +44,7 @@ public class Coordinate extends BaseResponse {
|
||||
@SerializedName("label")
|
||||
private String label;
|
||||
|
||||
public Coordinate (Double latitude, Double longitude, Double altitude, String label, String userId, String displayMode) {
|
||||
public Coordinate (Double latitude, Double longitude, Double altitude, String approximatedLocation, String label, String userId, String displayMode) {
|
||||
//if (!latitudeRange.contains(latitude)) throw new IllegalArgumentException("Inappropriate latitude value" + latitude);
|
||||
//if (!longtitudeRange.contains(longitude)) throw new IllegalArgumentException("Inappropriate longitude value" + longitude);
|
||||
|
||||
@ -53,6 +53,7 @@ public class Coordinate extends BaseResponse {
|
||||
this.altitude = altitude;
|
||||
this.label = label;
|
||||
this.userId = userId;
|
||||
this.approximatedLocation = approximatedLocation;
|
||||
this.displayMode = displayMode;
|
||||
}
|
||||
|
||||
|
@ -27,14 +27,16 @@ import com.google.android.gms.location.FusedLocationProviderClient;
|
||||
import com.google.android.gms.location.LocationServices;
|
||||
import com.google.android.gms.tasks.OnSuccessListener;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.mapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
@ -43,6 +45,7 @@ import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.geojson.Point.fromLngLat;
|
||||
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
||||
|
||||
public class BackgroundLocalizationService extends Service {
|
||||
@ -64,6 +67,8 @@ public class BackgroundLocalizationService extends Service {
|
||||
private Runnable mStatusChecker;
|
||||
private FusedLocationProviderClient mFusedLocationClient;
|
||||
|
||||
|
||||
|
||||
public BackgroundLocalizationService() {
|
||||
providers.add(LocationManager.GPS_PROVIDER);
|
||||
providers.add(LocationManager.NETWORK_PROVIDER);
|
||||
@ -74,6 +79,7 @@ public class BackgroundLocalizationService extends Service {
|
||||
new LocationListener(LocationManager.NETWORK_PROVIDER),
|
||||
new LocationListener(LocationManager.PASSIVE_PROVIDER)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -292,20 +298,27 @@ public class BackgroundLocalizationService extends Service {
|
||||
private CoordinateService coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
|
||||
ApproximatedLocalization approximatedLocalization;
|
||||
|
||||
private Task(Location location) {
|
||||
latitude = location.getLatitude();
|
||||
longitude = location.getLongitude();
|
||||
altitude = location.getAltitude();
|
||||
approximatedLocalization = new ApproximatedLocalization(mapUtils.loadJsonFromAsset(getApplicationContext(),"building.geojson"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Object[] objects) {
|
||||
/*
|
||||
Point point = approximatedLocalization.getPointerBuildingPart("Aule");
|
||||
Log.e("APPROXIMATED", String.valueOf(point));*/
|
||||
|
||||
try {
|
||||
Coordinate coordinate = new Coordinate(
|
||||
latitude,
|
||||
longitude,
|
||||
altitude,
|
||||
approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(longitude, latitude)),
|
||||
PrefUtils.getUserStatus(getApplicationContext()),
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
PrefUtils.getLocationLevel(getApplicationContext())
|
||||
|
@ -0,0 +1,64 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mapbox.geojson.BoundingBox;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.geojson.Geometry;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.geojson.Polygon;
|
||||
import com.mapbox.geojson.gson.BoundingBoxDeserializer;
|
||||
import com.mapbox.geojson.gson.GeoJsonAdapterFactory;
|
||||
import com.mapbox.geojson.gson.GeometryDeserializer;
|
||||
import com.mapbox.geojson.gson.PointDeserializer;
|
||||
import com.mapbox.turf.TurfJoins;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ApproximatedLocalization {
|
||||
private FeatureCollection buildingSchema = null;
|
||||
|
||||
public ApproximatedLocalization(String buildingObject){
|
||||
buildingSchema = fromJson(buildingObject);
|
||||
}
|
||||
|
||||
private FeatureCollection fromJson(@NonNull String json) {
|
||||
GsonBuilder gson = new GsonBuilder();
|
||||
gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create());
|
||||
gson.registerTypeAdapter(Point.class, new PointDeserializer());
|
||||
gson.registerTypeAdapter(Geometry.class, new GeometryDeserializer());
|
||||
gson.registerTypeAdapter(BoundingBox.class, new BoundingBoxDeserializer());
|
||||
return gson.create().fromJson(json, FeatureCollection.class);
|
||||
}
|
||||
|
||||
public String getNameOfBuildingPart(Point point) {
|
||||
|
||||
for(Feature feature : Objects.requireNonNull(buildingSchema.features())){
|
||||
boolean isInside = TurfJoins.inside(point, (Polygon) Objects.requireNonNull(feature.geometry()));
|
||||
|
||||
if (isInside){
|
||||
return Objects.requireNonNull(Objects.requireNonNull(feature.getStringProperty("name")));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/*
|
||||
public Point getMiddlePointForBuildingPart(String BuildingPart) {
|
||||
for(Feature feature : Objects.requireNonNull(buildingSchema.features())){
|
||||
String partName = feature.getStringProperty("name");
|
||||
|
||||
if(BuildingPart.equals(partName)) {
|
||||
JsonElement pointsList = feature.getProperty("point");
|
||||
return Point.fromLngLat(pointsList.getAsNumber().doubleValue(), pointsList.getAsJsonArray().get(1));
|
||||
}
|
||||
}
|
||||
|
||||
return Point.fromLngLat(0,0);
|
||||
}*/
|
||||
}
|
@ -2,6 +2,7 @@ package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.animation.TypeEvaluator;
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
@ -41,4 +42,5 @@ public class mapUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,19 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">@color/mapboxGray</color>
|
||||
<color name="colorPrimaryDark">@color/mapboxGrayDark10</color>
|
||||
<color name="colorAccent">@color/mapboxPink</color>
|
||||
<color name="msg_no_notes">#cf5e5e</color>
|
||||
<color name="colorPrimary">#476483</color>
|
||||
<color name="colorPrimaryDark">#3A3553</color>
|
||||
<color name="colorAccent">#CF0E0F</color>
|
||||
<color name="msg_no_notes">#89c3c3c3</color>
|
||||
<color name="hint_enter_note">#89c3c3c3</color>
|
||||
<color name="timestamp">#858585</color>
|
||||
<color name="note_list_text">#232323</color>
|
||||
|
||||
|
||||
<color name="colorWhite">#d1e200f6</color>
|
||||
<color name="white">#ffffff</color>
|
||||
<color name="colorWhiteTransparent">#80ffffff</color>
|
||||
|
||||
|
||||
<color name="materialGrey">#F5F5F5</color>
|
||||
<color name="materialDarkGrey">#dfdfdf</color>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user