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.34 KB
/
OtherUsersLocationModel.java
File metadata and controls
44 lines (33 loc) · 1.34 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.osmdroid.util.GeoPoint;
import java.util.ArrayList;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class OtherUsersLocationModel {
private ArrayList<GeoPoint> otherUsersLocations = new ArrayList<>();
private final UserModel userModel;
@Inject
public OtherUsersLocationModel(UserModel userModel) {
this.userModel = userModel;
}
public void setFromJson(JSONArray jsonArray) throws JSONException {
otherUsersLocations = new ArrayList<>(jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject locationObject = jsonArray.getJSONObject(i);
if (locationObject.getString("device").equals(userModel.getChangingDeviceToken())) {
continue; // Ignore own location
}
int latitudeE6 = Integer.parseInt(locationObject.getString("latitude"));
int longitudeE6 = Integer.parseInt(locationObject.getString("longitude"));
otherUsersLocations.add(
new GeoPoint(latitudeE6 / 1000000.0D, longitudeE6 / 1000000.0D));
}
}
public ArrayList<GeoPoint> getOtherUsersLocations() {
return otherUsersLocations;
}
}