aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/location/MozillaLocationProvider.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-12-20 17:22:21 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-12-20 17:22:21 +1300
commit0a8d47bec2a232aad6353d34a101eb82c9d4f7ae (patch)
tree2bad0ed0875b4e2ef751ffc6a7d25591cd6ae3fd /src/org/traccar/location/MozillaLocationProvider.java
parentc5594e16882ac3ec9215c47047e857566f8166b8 (diff)
downloadtrackermap-server-0a8d47bec2a232aad6353d34a101eb82c9d4f7ae.tar.gz
trackermap-server-0a8d47bec2a232aad6353d34a101eb82c9d4f7ae.tar.bz2
trackermap-server-0a8d47bec2a232aad6353d34a101eb82c9d4f7ae.zip
Improved network location providers
Diffstat (limited to 'src/org/traccar/location/MozillaLocationProvider.java')
-rw-r--r--src/org/traccar/location/MozillaLocationProvider.java53
1 files changed, 3 insertions, 50 deletions
diff --git a/src/org/traccar/location/MozillaLocationProvider.java b/src/org/traccar/location/MozillaLocationProvider.java
index cbfc19550..90be7c456 100644
--- a/src/org/traccar/location/MozillaLocationProvider.java
+++ b/src/org/traccar/location/MozillaLocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,63 +15,16 @@
*/
package org.traccar.location;
-import com.ning.http.client.AsyncCompletionHandler;
-import com.ning.http.client.Response;
-import org.traccar.Context;
-
-import javax.json.Json;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-
-public class MozillaLocationProvider extends BaseLocationProvider {
+public class MozillaLocationProvider extends UniversalLocationProvider {
private static final String URL = "https://location.services.mozilla.com/v1/geolocate";
- private String url;
- private String template;
-
public MozillaLocationProvider() {
this("test");
}
public MozillaLocationProvider(String key) {
- this.url = URL + "?key=" + key;
-
- template = new StringBuilder()
- .append("{\"cellTowers\":[{")
- .append("\"radioType\":\"gsm\",")
- .append("\"mobileCountryCode\":%d,")
- .append("\"mobileNetworkCode\":%d,")
- .append("\"locationAreaCode\":%d,")
- .append("\"cellId\":%d")
- .append("}]}")
- .toString();
- }
-
- protected void getLocation(int mcc, int mnc, long lac, long cid, final LocationProviderCallback callback) {
- String body = String.format(template, mcc, mnc, lac, cid);
- Context.getAsyncHttpClient().preparePost(url).setBody(body).execute(new AsyncCompletionHandler() {
- @Override
- public Object onCompleted(Response response) throws Exception {
- try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) {
- JsonObject json = reader.readObject().getJsonObject("location");
- if (json.containsKey("lat") && json.containsKey("lon")) {
- callback.onSuccess(
- json.getJsonNumber("lat").doubleValue(),
- json.getJsonNumber("lon").doubleValue());
- } else {
- callback.onFailure();
- }
- }
- return null;
- }
-
- @Override
- public void onThrowable(Throwable t) {
- callback.onFailure();
- }
- });
-
+ super(URL, key);
}
}