SimulateGps
SimulateGps copied to clipboard
setElapsedRealtimeNanos
/**
* setLocation 设置GPS的位置
*
*/
private void setLocation(double longitude, double latitude) {
Location location = new Location(mMockProviderName);
location.setTime(System.currentTimeMillis());
location.setLatitude(latitude);
location.setLongitude(longitude);
location.setAltitude(2.0f);
location.setAccuracy(3.0f);
if (Build.VERSION.SDK_INT > 16) {
//api 16以上的需要加上这一句才能模拟定位 , 也就是targetSdkVersion > 16
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
locationManager.setTestProviderLocation(mMockProviderName, location);
}