本文整理汇总了Java中android.location.Location.setElapsedRealtimeNanos方法的典型用法代码示例。如果您正苦于以下问题:Java Location.setElapsedRealtimeNanos方法的具体用法?Java Location.setElapsedRealtimeNanos怎么用?Java Location.setElapsedRealtimeNanos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Location
的用法示例。
在下文中一共展示了Location.setElapsedRealtimeNanos方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMockLocation
import android.location.Location; //导入方法依赖的package包/类
private Location createMockLocation() {
String longitudeString = longitudeInput.getText().toString();
String latitudeString = latitudeInput.getText().toString();
if (!longitudeString.isEmpty() && !latitudeString.isEmpty()) {
double longitude = Location.convert(longitudeString);
double latitude = Location.convert(latitudeString);
Location mockLocation = new Location("flp");
mockLocation.setLatitude(latitude);
mockLocation.setLongitude(longitude);
mockLocation.setAccuracy(1.0f);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
mockLocation.setTime(new Date().getTime());
return mockLocation;
} else {
throw new IllegalArgumentException();
}
}
示例2: setLocation
import android.location.Location; //导入方法依赖的package包/类
/**
* GPS定位需要不停的刷新经纬度值
*/
private static void setLocation(double latitude, double longitude) throws Exception{
try {
String providerStr = LocationManager.GPS_PROVIDER;
Location mockLocation = new Location(providerStr);
mockLocation.setLatitude(latitude);
mockLocation.setLongitude(longitude);
mockLocation.setAltitude(0); // 高程(米)
mockLocation.setBearing(0); // 方向(度)
mockLocation.setSpeed(0); //速度(米/秒)
mockLocation.setAccuracy(2); // 精度(米)
mockLocation.setTime(System.currentTimeMillis()); // 本地时间
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
//api 16以上的需要加上这一句才能模拟定位 , 也就是targetSdkVersion > 16
mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
locationManager.setTestProviderLocation(providerStr, mockLocation);
} catch (Exception e) {
// 防止用户在软件运行过程中关闭模拟位置或选择其他应用
stopMockLocation();
throw e;
}
}
示例3: toSysLocation
import android.location.Location; //导入方法依赖的package包/类
public Location toSysLocation() {
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setAccuracy(8f);
Bundle extraBundle = new Bundle();
location.setBearing(bearing);
Reflect.on(location).call("setIsFromMockProvider", false);
location.setLatitude(latitude);
location.setLongitude(longitude);
location.setSpeed(speed);
location.setTime(System.currentTimeMillis());
location.setExtras(extraBundle);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
location.setElapsedRealtimeNanos(277000000);
}
int svCount = VirtualGPSSatalines.get().getSvCount();
extraBundle.putInt("satellites", svCount);
extraBundle.putInt("satellitesvalue", svCount);
return location;
}
示例4: _getLocation
import android.location.Location; //导入方法依赖的package包/类
/**
* If we have any coverage information, returns an estimate of that coverage.
* For convenience, we use the standard Location record as it contains a center
* point and radius (accuracy).
*
* @return Coverage estimate for emitter or null it does not exist.
*/
private Location _getLocation() {
if (coverage == null)
return null;
final Location location = new Location(BackendService.LOCATION_PROVIDER);
Long timeMs = System.currentTimeMillis();
location.setTime(timeMs);
if (Build.VERSION.SDK_INT >= 17)
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
location.setLatitude(coverage.latitude);
location.setLongitude(coverage.longitude);
// At this point, accuracy is the maximum coverage area. Scale it based on
// the ASU as we assume we are closer to the center of the coverage if we
// have a high signal.
float scale = BackendService.MAXIMUM_ASU - asu + BackendService.MINIMUM_ASU;
scale = scale / BackendService.MAXIMUM_ASU;
float accuracy = coverage.radius * scale;
// Hard limit the minimum accuracy based on the type of emitter
location.setAccuracy(Math.max(accuracy,ourCharacteristics.minimumRange));
return location;
}
示例5: result
import android.location.Location; //导入方法依赖的package包/类
public Location result() {
if (count < 1)
return null;
final Location location = new Location(BackendService.LOCATION_PROVIDER);
location.setTime(timeMs);
if (Build.VERSION.SDK_INT >= 17)
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
location.setLatitude(meanLat);
location.setLongitude(meanLon);
if (count == 1) {
location.setAccuracy(reportAccuracy);
} else {
//double varLat = sLat / (wSumLat - 1);
//double varLon = sLon / (wSumLon - 1);
double varLat = sLat / (wSumLat - wSum2Lat / wSumLat);
double varLon = sLon / (wSumLon - wSum2Lon / wSumLon);
double sdLat = Math.sqrt(varLat);
double sdLon = Math.sqrt(varLon);
//Log.d(TAG, "result() sLat=" + sLat + ", wSumLat=" + wSumLat + ", wSum2Lat=" + wSum2Lat + ", varLat=" + varLat + ", sdLat=" + sdLat);
double sdMetersLat = sdLat * BackendService.DEG_TO_METER;
double cosLat = Math.max(BackendService.MIN_COS, Math.cos(Math.toRadians(meanLat)));
double sdMetersLon = sdLon * BackendService.DEG_TO_METER * cosLat;
float acc = (float) Math.max(sdMetersLat, sdMetersLon);
location.setAccuracy(acc);
}
Bundle extras = new Bundle();
extras.putLong("AVERAGED_OF", count);
location.setExtras(extras);
return location;
}
示例6: getLocation
import android.location.Location; //导入方法依赖的package包/类
public synchronized Location getLocation() {
Long timeMs = System.currentTimeMillis();
final Location location = new Location(BackendService.LOCATION_PROVIDER);
predict(timeMs);
location.setTime(timeMs);
if (Build.VERSION.SDK_INT >= 17)
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
location.setLatitude(mLatTracker.getPosition());
location.setLongitude(mLonTracker.getPosition());
if (mAltTracker != null)
location.setAltitude(mAltTracker.getPosition());
float accuracy = (float) (mLatTracker.getAccuracy() * BackendService.DEG_TO_METER);
if (accuracy < MIN_ACCURACY)
accuracy = MIN_ACCURACY;
location.setAccuracy(accuracy);
// Derive speed from degrees/ms in lat and lon
double latVeolocity = mLatTracker.getVelocity() * BackendService.DEG_TO_METER;
double lonVeolocity = mLonTracker.getVelocity() * BackendService.DEG_TO_METER *
Math.cos(Math.toRadians(location.getLatitude()));
float speed = (float) Math.sqrt((latVeolocity*latVeolocity)+(lonVeolocity*lonVeolocity));
location.setSpeed(speed);
// Compute bearing only if we are moving. Report old bearing
// if we are below our threshold for moving.
if (speed > MOVING_THRESHOLD) {
mBearing = (float) Math.toDegrees(Math.atan2(latVeolocity, lonVeolocity));
}
location.setBearing(mBearing);
Bundle extras = new Bundle();
extras.putLong("AVERAGED_OF", samples);
location.setExtras(extras);
return location;
}
示例7: scheduleMockGps
import android.location.Location; //导入方法依赖的package包/类
private void scheduleMockGps(final Context context) {
Gps gps;
synchronized (mMockGps) {
gps = mMockGps[0];
}
if (null == gps) {
return;
}
if (!Macro.RealGps) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(gps.mLatitude);
location.setLongitude(gps.mLongitude);
location.setAltitude(0);
location.setBearing(0);
location.setSpeed(0);
location.setAccuracy(2);
location.setTime(System.currentTimeMillis());
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
locationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, location);
}
new Handler(context.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
scheduleMockGps(context);
}
}, 1000);
}
示例8: postNextLocation
import android.location.Location; //导入方法依赖的package包/类
private void postNextLocation() {
int nextIndex = (mCurrentLocationIndex + 1) % mLocations.size();
Location nextLocation = new Location(mLocations.get(nextIndex));
nextLocation.setTime(System.currentTimeMillis());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
nextLocation.setElapsedRealtimeNanos(System.nanoTime());
}
LocationServices.FusedLocationApi
.setMockLocation(mClient, nextLocation);
Log.i(TAG, "New location: " + nextLocation);
mCurrentLocationIndex = nextIndex;
}