aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/location/OpenCellIdLocationProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/location/OpenCellIdLocationProvider.java')
-rw-r--r--src/org/traccar/location/OpenCellIdLocationProvider.java56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/org/traccar/location/OpenCellIdLocationProvider.java b/src/org/traccar/location/OpenCellIdLocationProvider.java
index d5d1b0ace..b45797b80 100644
--- a/src/org/traccar/location/OpenCellIdLocationProvider.java
+++ b/src/org/traccar/location/OpenCellIdLocationProvider.java
@@ -18,12 +18,14 @@ package org.traccar.location;
import com.ning.http.client.AsyncCompletionHandler;
import com.ning.http.client.Response;
import org.traccar.Context;
+import org.traccar.model.CellTower;
+import org.traccar.model.Network;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
-public class OpenCellIdLocationProvider extends BaseLocationProvider {
+public class OpenCellIdLocationProvider implements LocationProvider {
private String url;
@@ -35,29 +37,39 @@ public class OpenCellIdLocationProvider extends BaseLocationProvider {
this.url = url + "?format=json&mcc=%d&mnc=%d&lac=%d&cellid=%d&key=" + key;
}
- protected void getLocation(int mcc, int mnc, long lac, long cid, final LocationProviderCallback callback) {
- Context.getAsyncHttpClient().prepareGet(String.format(url, mcc, mnc, lac, cid))
- .execute(new AsyncCompletionHandler() {
- @Override
- public Object onCompleted(Response response) throws Exception {
- try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) {
- JsonObject json = reader.readObject();
- if (json.containsKey("lat") && json.containsKey("lon")) {
- callback.onSuccess(
- json.getJsonNumber("lat").doubleValue(),
- json.getJsonNumber("lon").doubleValue());
- } else {
- callback.onFailure();
+ @Override
+ public void getLocation(Network network, final LocationProviderCallback callback) {
+ if (network.getCellTowers() != null && !network.getCellTowers().isEmpty()) {
+
+ CellTower cellTower = network.getCellTowers().iterator().next();
+ String request = String.format(url, cellTower.getMobileCountryCode(), cellTower.getMobileNetworkCode(),
+ cellTower.getLocationAreaCode(), cellTower.getCellId());
+
+ Context.getAsyncHttpClient().prepareGet(request).execute(new AsyncCompletionHandler() {
+ @Override
+ public Object onCompleted(Response response) throws Exception {
+ try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) {
+ JsonObject json = reader.readObject();
+ if (json.containsKey("lat") && json.containsKey("lon")) {
+ callback.onSuccess(
+ json.getJsonNumber("lat").doubleValue(),
+ json.getJsonNumber("lon").doubleValue(), 0);
+ } else {
+ callback.onFailure();
+ }
}
+ return null;
}
- return null;
- }
-
- @Override
- public void onThrowable(Throwable t) {
- callback.onFailure();
- }
- });
+
+ @Override
+ public void onThrowable(Throwable t) {
+ callback.onFailure();
+ }
+ });
+
+ } else {
+ callback.onFailure();
+ }
}
}