当前位置: 首页>>代码示例>>Java>>正文


Java Location.setAccuracy方法代码示例

本文整理汇总了Java中android.location.Location.setAccuracy方法的典型用法代码示例。如果您正苦于以下问题:Java Location.setAccuracy方法的具体用法?Java Location.setAccuracy怎么用?Java Location.setAccuracy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.location.Location的用法示例。


在下文中一共展示了Location.setAccuracy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:MockLocationsActivity.java

示例2: mockLocation

import android.location.Location; //导入方法依赖的package包/类
/**
 * Here we build the new mock {@link Location} object and fill in as much information we can calculate.
 *
 * @param point taken from the points list, converts this to a {@link Location}.
 * @return a {@link Location} object with as much information filled in as possible.
 * @since 2.2.0
 */
private Location mockLocation(Point point) {
  location = new Location(MockLocationEngine.class.getName());
  location.setLatitude(point.latitude());
  location.setLongitude(point.longitude());

  // Need to convert speed to meters/second as specified in Android's Location object documentation.
  float speedInMeterPerSec = (float) (((speed * 1.609344) * 1000) / (60 * 60));
  location.setSpeed(speedInMeterPerSec);

  if (points.size() >= 2) {
    double bearing = TurfMeasurement.bearing(point, points.get(1));
    Timber.v("Bearing value %f", bearing);
    location.setBearing((float) bearing);
  }

  location.setAccuracy(3f);
  location.setTime(System.currentTimeMillis());

  return location;
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:28,代码来源:MockLocationEngine.java

示例3: mockLocation

import android.location.Location; //导入方法依赖的package包/类
/**
 * Here we build the new mock {@link Location} object and fill in as much information we can calculate.
 *
 * @param position taken from the positions list, converts this to a {@link Location}.
 * @return a {@link Location} object with as much information filled in as possible.
 * @since 2.2.0
 */
private Location mockLocation(Position position) {
  lastLocation = new Location(MockLocationEngine.class.getName());
  lastLocation.setLatitude(position.getLatitude());
  lastLocation.setLongitude(position.getLongitude());

  // Need to convert speed to meters/second as specified in Android's Location object documentation.
  float speedInMeterPerSec = (float) (((speed * 1.609344) * 1000) / (60 * 60));
  lastLocation.setSpeed(speedInMeterPerSec);

  if (positions.size() >= 2) {
    double bearing = TurfMeasurement.bearing(position, positions.get(1));
    lastLocation.setBearing((float) bearing);
  }

  lastLocation.setAccuracy(3f);
  lastLocation.setTime(SystemClock.elapsedRealtime());

  return lastLocation;
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:27,代码来源:MockLocationEngine.java

示例4: 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;
    }
}
 
开发者ID:littleRich,项目名称:VirtualLocation,代码行数:26,代码来源:LocationUtil.java

示例5: 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;
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:20,代码来源:VLocation.java

示例6: deserialize

import android.location.Location; //导入方法依赖的package包/类
public Location deserialize(JsonElement je, Type type,
                            JsonDeserializationContext jdc) {
    JsonObject jsonObject = je.getAsJsonObject();
    Location location = new Location(jsonObject.getAsJsonPrimitive("mProvider").getAsString());
    location.setAccuracy(jsonObject.getAsJsonPrimitive("mAccuracy").getAsFloat());
    location.setLatitude(jsonObject.getAsJsonPrimitive("mLatitude").getAsDouble());
    location.setLongitude(jsonObject.getAsJsonPrimitive("mLongitude").getAsDouble());
    location.setTime(jsonObject.getAsJsonPrimitive("mTime").getAsLong());
    location.setSpeed(jsonObject.getAsJsonPrimitive("mSpeed").getAsFloat());
    location.setBearing(jsonObject.getAsJsonPrimitive("mBearing").getAsFloat());
    return location;
}
 
开发者ID:hypertrack,项目名称:hypertrack-live-android,代码行数:13,代码来源:LocationDeserializer.java

示例7: testOpenLocateConstructor

import android.location.Location; //导入方法依赖的package包/类
@Test
public void testOpenLocateConstructor() {
    // Given
    double lat = 10.40;
    double lng = 10.234;
    double accuracy = 40.43;
    boolean adOptOut = true;
    String adId = "1234";

    Location location = new Location("");
    location.setLatitude(lat);
    location.setLongitude(lng);
    location.setAccuracy((float) accuracy);

    AdvertisingIdClient.Info info = new AdvertisingIdClient.Info(adId, adOptOut);

    OpenLocateLocation openLocateLocation = new OpenLocateLocation(location, info, null);

    // When
    JSONObject json = openLocateLocation.getJson();

    // Then
    assertNotNull(openLocateLocation);
    try {
        assertEquals(json.getDouble(OpenLocateLocation.Keys.LATITUDE), lat, 0.0d);
        assertEquals(json.getDouble(OpenLocateLocation.Keys.LONGITUDE), lng, 0.0d);
        assertEquals(json.getDouble(OpenLocateLocation.Keys.HORIZONTAL_ACCURACY), accuracy, 0.1);
        assertEquals(json.getBoolean(OpenLocateLocation.Keys.AD_OPT_OUT), adOptOut);
        assertEquals(json.getString(OpenLocateLocation.Keys.AD_ID), adId);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:34,代码来源:OpenLocateLocationTests.java

示例8: getLocation

import android.location.Location; //导入方法依赖的package包/类
/**
 * User facing location value. Differs from internal one in that we don't report
 * locations that are guarded due to being new or moved. And we work internally
 * with radius values that fit within a bounding box but we report a radius that
 * extends to the corners of the bounding box.
 *
 * @return The coverage estimate for our RF emitter or null if we don't trust our
 * information.
 */
public  Location getLocation() {
    if ((trust < REQUIRED_TRUST) || (status == EmitterStatus.STATUS_BLACKLISTED))
        return null;
    Location boundaryBoxSized = _getLocation();
    if (boundaryBoxSized == null)
        return null;

    // Our radius is sized to fit be tangent to the sides of the
    // bounding box. But we really ought to cover the corners of
    // the box, so multiply by the square root of 2 to convert.
    boundaryBoxSized.setAccuracy((boundaryBoxSized.getAccuracy() * 1.41421356f));
    return boundaryBoxSized;
}
 
开发者ID:n76,项目名称:DejaVu,代码行数:23,代码来源:RfEmitter.java

示例9: _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;
}
 
开发者ID:n76,项目名称:DejaVu,代码行数:34,代码来源:RfEmitter.java

示例10: setLocation

import android.location.Location; //导入方法依赖的package包/类
private void setLocation(String provider, float accuracy, double latitude, double longitude) {
	lastFix = new Location(provider);
	lastFix.setLatitude(latitude);
	lastFix.setLongitude(longitude);
	lastFix.setAccuracy(accuracy);
	setLocation(lastFix);
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:8,代码来源:AbstractTransactionActivity.java

示例11: 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;
}
 
开发者ID:n76,项目名称:DejaVu,代码行数:39,代码来源:Kalman.java

示例12: trackLocation

import android.location.Location; //导入方法依赖的package包/类
@ReactMethod
public void trackLocation(ReadableMap position) {
    final Location location = new Location("RNBatch");
    location.setLongitude(position.getDouble("longitude"));
    location.setLatitude(position.getDouble("latitude"));
    location.setAccuracy((float) position.getDouble("accuracy"));

    Batch.User.trackLocation(location);
}
 
开发者ID:dangerfarms,项目名称:react-native-batch,代码行数:10,代码来源:RNBatchModule.java

示例13: newLocation

import android.location.Location; //导入方法依赖的package包/类
private Location newLocation(double lat, double lon, double alt) {
    Location l = new Location("MOCK");
    l.setLatitude(lat);
    l.setLongitude(lon);
    l.setAltitude(alt);
    l.setAccuracy(0.5f);

    return l;
}
 
开发者ID:rsippl,项目名称:AndroidProgramming3e,代码行数:10,代码来源:MockWalk.java

示例14: 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);
}
 
开发者ID:littleRich,项目名称:AutoInteraction-Library,代码行数:29,代码来源:GpsMocker.java

示例15: doInBackground

import android.location.Location; //导入方法依赖的package包/类
@Override
protected Integer doInBackground(Integer... params) {
    LocSample l = m_rgSamples[params[0]];
    m_Loc = new Location("MFB");
    m_Loc.setAccuracy((float) l.HError);
    m_Loc.setAltitude(l.Alt);
    m_Loc.setLatitude(l.Latitude);
    m_Loc.setLongitude(l.Longitude);
    m_Loc.setSpeed((float) (l.Speed / MFBConstants.MPS_TO_KNOTS)); // locsample is in Knots, need to go back to MPS
    m_Loc.setTime(l.TimeStamp.getTime());
    return params[0];
}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:13,代码来源:GPSSim.java


注:本文中的android.location.Location.setAccuracy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。