當前位置: 首頁>>代碼示例>>Java>>正文


Java Location.setBearing方法代碼示例

本文整理匯總了Java中android.location.Location.setBearing方法的典型用法代碼示例。如果您正苦於以下問題:Java Location.setBearing方法的具體用法?Java Location.setBearing怎麽用?Java Location.setBearing使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.location.Location的用法示例。


在下文中一共展示了Location.setBearing方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例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 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

示例3: 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

示例4: 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

示例5: getSnappedLocation

import android.location.Location; //導入方法依賴的package包/類
@Override
public Location getSnappedLocation(Location location, RouteProgress routeProgress,
                                   @Nullable List<Point> coords) {
  Location snappedLocation = snapLocationLatLng(location, coords);
  snappedLocation.setBearing(snapLocationBearing(routeProgress));
  return snappedLocation;
}
 
開發者ID:mapbox,項目名稱:mapbox-navigation-android,代碼行數:8,代碼來源:SnapToRoute.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: 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

示例8: 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


注:本文中的android.location.Location.setBearing方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。