本文整理汇总了Java中org.microg.nlp.api.LocationHelper类的典型用法代码示例。如果您正苦于以下问题:Java LocationHelper类的具体用法?Java LocationHelper怎么用?Java LocationHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocationHelper类属于org.microg.nlp.api包,在下文中一共展示了LocationHelper类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onOpen
import org.microg.nlp.api.LocationHelper; //导入依赖的package包/类
@Override
protected void onOpen() {
super.onOpen();
regular = new Thread(new Runnable() {
@Override
public void run() {
synchronized (regular) {
while (!regular.isInterrupted()) {
try {
regular.wait(60000);
} catch (InterruptedException e) {
return;
}
Location location = LocationHelper.create("random", random.nextDouble() * 90, random.nextDouble() * 90, random.nextFloat() * 90);
Log.d(TAG, "Just reported: " + location);
report(location);
}
}
}
});
regular.start();
}
开发者ID:microg,项目名称:android_external_UnifiedNlpApi,代码行数:23,代码来源:ThirdSampleService.java
示例2: update
import org.microg.nlp.api.LocationHelper; //导入依赖的package包/类
@Override
protected Location update() {
start();
if (lp == null) return null;
CellInfo[] infos = lp.getAll();
if (infos.length == 0) return null;
double lng = 0d;
double lat = 0d;
for(CellInfo c : infos) {
lng += c.lng;
lat += c.lat;
}
lng /= infos.length;
lat /= infos.length;
float acc = (float)(800d / infos.length);
Log.d(TAG, "update (" + lat + "," + lng + ")");
return LocationHelper.create("gsm", lat, lng, acc);
}
开发者ID:rtreffer,项目名称:LocalGSMLocationProvider,代码行数:24,代码来源:GSMService.java
示例3: update
import org.microg.nlp.api.LocationHelper; //导入依赖的package包/类
@Override
protected Location update() {
if (System.currentTimeMillis() % 60000 > 2000) {
Log.d(TAG, "I decided not to answer now...");
return null;
}
Location location = LocationHelper.create("sample", 42, 42, 42);
Log.d(TAG, "I was asked for location and I answer: " + location);
return location;
}
开发者ID:microg,项目名称:android_external_UnifiedNlpApi,代码行数:11,代码来源:SampleBackendService.java
示例4: wloc_return_position
import org.microg.nlp.api.LocationHelper; //导入依赖的package包/类
@Override
protected void wloc_return_position(int ret, double lat, double lon, float radius, short ccode, float cog) {
Log.d(TAG, String.format("wloc_return_position ret=%d lat=%f lon=%f radius=%f ccode=%d cog=%f", ret, lat, lon, radius, ccode, cog));
if (ret == WLOC_OK) {
Location location = LocationHelper.create("libwlocate", lat, lon, radius);
if (cog != -1) {
location.setBearing(cog);
}
report(location);
}
}
开发者ID:microg,项目名称:OpenWlanMapNlpBackend,代码行数:12,代码来源:BackendService.java
示例5: update
import org.microg.nlp.api.LocationHelper; //导入依赖的package包/类
@Override
protected Location update() {
Location location = LocationHelper.create("second-sample", 13, 13, (System.currentTimeMillis() / 1000) % 100);
Log.d(TAG, "I was asked for location and I answer: " + location);
return location;
}
开发者ID:microg,项目名称:android_external_UnifiedNlpApi,代码行数:7,代码来源:SecondSampleService.java
示例6: startCalculate
import org.microg.nlp.api.LocationHelper; //导入依赖的package包/类
private synchronized void startCalculate() {
if (thread != null) return;
if (lastRequestTime + RATE_LIMIT_MS > System.currentTimeMillis()) return;
final Set<WiFi> wiFis = this.wiFis;
final Set<Cell> cells = this.cells;
if ((cells == null || cells.isEmpty()) && (wiFis == null || wiFis.size() < 2)) return;
try {
final String request = createRequest(cells, wiFis);
if (request.equals(lastRequest)) {
if (replay) {
Log.d(TAG, "No data changes, replaying location " + lastResponse);
lastResponse = LocationHelper.create(PROVIDER, lastResponse.getLatitude(), lastResponse.getLongitude(), lastResponse.getAccuracy());
report(lastResponse);
}
return;
}
replay = false;
thread = new Thread(new Runnable() {
@Override
public void run() {
HttpURLConnection conn = null;
Location response = null;
try {
conn = (HttpURLConnection) new URL(String.format(SERVICE_URL, API_KEY)).openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
Log.d(TAG, "request: " + request);
conn.getOutputStream().write(request.getBytes());
String r = new String(readStreamToEnd(conn.getInputStream()));
Log.d(TAG, "response: " + r);
JSONObject responseJson = new JSONObject(r);
double lat = responseJson.getJSONObject("location").getDouble("lat");
double lon = responseJson.getJSONObject("location").getDouble("lng");
double acc = responseJson.getDouble("accuracy");
response = LocationHelper.create(PROVIDER, lat, lon, (float) acc);
report(response);
} catch (IOException | JSONException e) {
if (conn != null) {
InputStream is = conn.getErrorStream();
if (is != null) {
try {
String error = new String(readStreamToEnd(is));
Log.w(TAG, "Error: " + error);
} catch (Exception ignored) {
}
}
}
Log.w(TAG, e);
}
lastRequest = request;
lastResponse = response;
lastRequestTime = System.currentTimeMillis();
thread = null;
}
});
thread.start();
} catch (Exception e) {
Log.w(TAG, e);
}
}
开发者ID:microg,项目名称:IchnaeaNlpBackend,代码行数:62,代码来源:BackendService.java
示例7: weightedAverage
import org.microg.nlp.api.LocationHelper; //导入依赖的package包/类
public Location weightedAverage(String source, Collection<Location> locations) {
Location rslt;
if (locations == null || locations.size() == 0) {
return null;
}
int num = locations.size();
int totalWeight = 0;
double latitude = 0;
double longitude = 0;
float accuracy = 0;
int altitudes = 0;
double altitude = 0;
for (Location value : locations) {
if (value != null) {
// Create weight value based on accuracy. Higher accuracy
// (lower tower radius/range) towers get higher weight.
float thisAcc = value.getAccuracy();
if (thisAcc < 1f)
thisAcc = 1f;
int wgt = (int) (100000f / thisAcc);
if (wgt < 1)
wgt = 1;
latitude += (value.getLatitude() * wgt);
longitude += (value.getLongitude() * wgt);
accuracy += (value.getAccuracy() * wgt);
totalWeight += wgt;
// if (DEBUG) Log.i(TAG, "(lat="+ latitude + ", lng=" + longitude + ", acc=" + accuracy + ") / wgt=" + totalWeight );
if (value.hasAltitude()) {
altitude += value.getAltitude();
altitudes++;
}
}
}
latitude = latitude / totalWeight;
longitude = longitude / totalWeight;
accuracy = accuracy / totalWeight;
altitude = altitude / altitudes;
Bundle extras = new Bundle();
extras.putInt("AVERAGED_OF", num);
// if (DEBUG) Log.i(TAG, "Location est (lat="+ latitude + ", lng=" + longitude + ", acc=" + accuracy);
if (altitudes > 0) {
rslt = LocationHelper.create(source,
latitude,
longitude,
altitude,
accuracy,
extras);
} else {
rslt = LocationHelper.create(source,
latitude,
longitude,
accuracy,
extras);
}
rslt.setTime(System.currentTimeMillis());
return rslt;
}
开发者ID:n76,项目名称:Local-GSM-Backend,代码行数:66,代码来源:TelephonyHelper.java
示例8: toLocation
import org.microg.nlp.api.LocationHelper; //导入依赖的package包/类
public Location toLocation() {
return LocationHelper.create("gsm", (float) lat / samples, (float) lng / samples, (float) rng, new Bundle());
}
开发者ID:n76,项目名称:Local-GSM-Backend,代码行数:4,代码来源:LocationCalculator.java
注:本文中的org.microg.nlp.api.LocationHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论