forked from criticalmaps/criticalmaps-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOwnLocationModel.java
More file actions
46 lines (35 loc) · 1.23 KB
/
OwnLocationModel.java
File metadata and controls
46 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package de.stephanlindauer.criticalmaps.model;
import androidx.annotation.NonNull;
import org.json.JSONException;
import org.json.JSONObject;
import org.maplibre.android.geometry.LatLng;
import javax.inject.Inject;
import javax.inject.Singleton;
import timber.log.Timber;
@Singleton
public class OwnLocationModel {
private static final float ACCURACY_PRECISE_THRESHOLD = 50.0f; //meters
public LatLng ownLocation;
private boolean isLocationPrecise;
@Inject
public OwnLocationModel() {
}
public void setLocation(@NonNull LatLng location, float accuracy) {
ownLocation = location;
isLocationPrecise = accuracy < ACCURACY_PRECISE_THRESHOLD;
}
public boolean hasPreciseLocation() {
return ownLocation != null && isLocationPrecise;
}
@NonNull
public JSONObject getLocationJson() {
JSONObject locationObject = new JSONObject();
try {
locationObject.put("longitude", Integer.toString((int) (ownLocation.getLongitude() * 1000000.0D)));
locationObject.put("latitude", Integer.toString((int) (ownLocation.getLatitude() * 1000000.0D)));
} catch (JSONException e) {
Timber.e(e);
}
return locationObject;
}
}