Send middle of polygon in approximated mode
This commit is contained in:
parent
77b7c50e4e
commit
aa3c2eb9b8
@ -3,7 +3,9 @@
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Skrzydło B"
|
||||
"name": "Skrzydło B",
|
||||
"longitude" : 52.466669,
|
||||
"latitude" : 16.926624
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
@ -89,7 +91,9 @@
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Biblioteka"
|
||||
"name": "Biblioteka",
|
||||
"longitude" : 52.467351,
|
||||
"latitude" : 16.926900
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
@ -139,7 +143,9 @@
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Łącznik"
|
||||
"name": "Łącznik",
|
||||
"longitude" : 52.466619,
|
||||
"latitude" : 16.926860
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
@ -173,7 +179,9 @@
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Skrzydło A"
|
||||
"name": "Skrzydło A",
|
||||
"longitude" : 52.466559,
|
||||
"latitude" : 16.927163
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
@ -231,7 +239,10 @@
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Aule"
|
||||
"name": "Aule",
|
||||
"longitude" : 52.467114,
|
||||
"latitude" : 16.927621
|
||||
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
@ -334,7 +345,8 @@
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Hol",
|
||||
"point" : [52.467088, 16.927150]
|
||||
"longitude" : 52.4671021,
|
||||
"latitude" : 16.927122
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
|
@ -19,6 +19,7 @@ import android.widget.Toast;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -40,9 +41,10 @@ public class SharingFragment extends PreferenceFragment {
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
locationLevelMapping = new HashMap<Integer, String>();
|
||||
locationLevelMapping.put(0,"presence");
|
||||
locationLevelMapping.put(1,"approximated");
|
||||
locationLevelMapping.put(2,"exact");
|
||||
|
||||
locationLevelMapping.put(0, SharingLevel.PRESENCE.toString());
|
||||
locationLevelMapping.put(1, SharingLevel.APPROXIMATED.toString());
|
||||
locationLevelMapping.put(2, SharingLevel.EXACT.toString());
|
||||
|
||||
addPreferencesFromResource(R.layout.pref_sharing);
|
||||
Preference manualStatus = findPreference("key_manual_status");
|
||||
@ -60,8 +62,8 @@ public class SharingFragment extends PreferenceFragment {
|
||||
});
|
||||
|
||||
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
ListPreference lp = (ListPreference) preference;
|
||||
PrefUtils.storeLocationMode(getApplicationContext(),locationLevelMapping.get(Integer.parseInt((String) newValue)));
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
|
@ -47,6 +47,7 @@ public class Coordinate extends BaseResponse {
|
||||
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);
|
||||
//if (approximatedLocation == null) throw new IllegalArgumentException("Inappropriate approximatedLocation");
|
||||
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
|
@ -33,6 +33,7 @@ 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.SharingLevel;
|
||||
import com.uam.wmi.findmytutor.utils.mapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -45,7 +46,6 @@ 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 {
|
||||
@ -68,7 +68,6 @@ public class BackgroundLocalizationService extends Service {
|
||||
private FusedLocationProviderClient mFusedLocationClient;
|
||||
|
||||
|
||||
|
||||
public BackgroundLocalizationService() {
|
||||
providers.add(LocationManager.GPS_PROVIDER);
|
||||
providers.add(LocationManager.NETWORK_PROVIDER);
|
||||
@ -289,36 +288,49 @@ public class BackgroundLocalizationService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private class Task extends AsyncTask {
|
||||
ApproximatedLocalization approximatedLocalization;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Double altitude;
|
||||
|
||||
private String approximatedBuildingPart = null;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
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"));
|
||||
approximatedBuildingPart = approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(longitude, latitude));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Object[] objects) {
|
||||
/*
|
||||
Point point = approximatedLocalization.getPointerBuildingPart("Aule");
|
||||
Log.e("APPROXIMATED", String.valueOf(point));*/
|
||||
|
||||
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.PRESENCE.toString())) {
|
||||
longitude = 52.467491;
|
||||
latitude = 16.926782;
|
||||
Log.e(TAG,"PRESENCE");
|
||||
} else if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.APPROXIMATED.toString())) {
|
||||
List<Double> points = approximatedLocalization.getPointerBuildingPart(approximatedBuildingPart);
|
||||
|
||||
latitude = points.get(0);
|
||||
longitude = points.get(1);
|
||||
Log.e(TAG,"APPROXIMATED");
|
||||
}else {
|
||||
Log.e(TAG,"EXACT");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Coordinate coordinate = new Coordinate(
|
||||
latitude,
|
||||
longitude,
|
||||
altitude,
|
||||
approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(longitude, latitude)),
|
||||
approximatedBuildingPart,
|
||||
PrefUtils.getUserStatus(getApplicationContext()),
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
PrefUtils.getLocationLevel(getApplicationContext())
|
||||
|
@ -1,8 +1,12 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mapbox.geojson.BoundingBox;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
@ -15,8 +19,13 @@ import com.mapbox.geojson.gson.GeometryDeserializer;
|
||||
import com.mapbox.geojson.gson.PointDeserializer;
|
||||
import com.mapbox.turf.TurfJoins;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
;
|
||||
|
||||
public class ApproximatedLocalization {
|
||||
private FeatureCollection buildingSchema = null;
|
||||
|
||||
@ -26,10 +35,12 @@ public class ApproximatedLocalization {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -38,24 +49,31 @@ public class ApproximatedLocalization {
|
||||
for (Feature feature : Objects.requireNonNull(buildingSchema.features())) {
|
||||
boolean isInside = TurfJoins.inside(point, (Polygon) Objects.requireNonNull(feature.geometry()));
|
||||
|
||||
if (isInside){
|
||||
if (isInside)
|
||||
return Objects.requireNonNull(Objects.requireNonNull(feature.getStringProperty("name")));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/*
|
||||
public Point getMiddlePointForBuildingPart(String BuildingPart) {
|
||||
|
||||
public List<Double> getPointerBuildingPart(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));
|
||||
if (buildingPart != null && buildingPart.equals(partName)) {
|
||||
Double longitude = feature.getNumberProperty("longitude").doubleValue();
|
||||
Double latitude = feature.getNumberProperty("latitude").doubleValue();
|
||||
|
||||
List<Double> list = Arrays.asList(longitude,latitude);
|
||||
|
||||
Log.e("APPROX",partName + " " + buildingPart + list);
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return Point.fromLngLat(0,0);
|
||||
}*/
|
||||
return Arrays.asList(0.0,0.0);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
public enum SharingLevel {
|
||||
PRESENCE("presence"),
|
||||
APPROXIMATED("approximated"),
|
||||
EXACT("exact");
|
||||
|
||||
private final String text;
|
||||
|
||||
SharingLevel(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user