forked from criticalmaps/criticalmaps-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOtherUsersLocationModel.java
More file actions
44 lines (33 loc) · 1.35 KB
/
OtherUsersLocationModel.java
File metadata and controls
44 lines (33 loc) · 1.35 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
package de.stephanlindauer.criticalmaps.model;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.maplibre.android.geometry.LatLng;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class OtherUsersLocationModel {
private final Map<String, LatLng> otherUsersLocations = new HashMap<>();
private final UserModel userModel;
@Inject
public OtherUsersLocationModel(UserModel userModel) {
this.userModel = userModel;
}
public void setFromJson(JSONArray jsonArray) throws JSONException {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject locationObject = jsonArray.getJSONObject(i);
if (locationObject.getString("device").equals(userModel.getChangingDeviceToken())) {
continue; // Ignore own location
}
String deviceId = locationObject.getString("device");
int latitudeE6 = Integer.parseInt(locationObject.getString("latitude"));
int longitudeE6 = Integer.parseInt(locationObject.getString("longitude"));
otherUsersLocations.put(deviceId, new LatLng(latitudeE6 / 1E6, longitudeE6 / 1E6));
}
}
public Map<String, LatLng> getOtherUsersLocations() {
return otherUsersLocations;
}
}