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


Java LengthUnit类代码示例

本文整理汇总了Java中com.javadocmd.simplelatlng.util.LengthUnit的典型用法代码示例。如果您正苦于以下问题:Java LengthUnit类的具体用法?Java LengthUnit怎么用?Java LengthUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LengthUnit类属于com.javadocmd.simplelatlng.util包,在下文中一共展示了LengthUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAddress

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
@RetryOnFailure(attempts = 5, delay = 1, unit = TimeUnit.MINUTES)
public Address getAddress(double lat, double lng) throws IOException {
	LatLng query = new LatLng(lat, lng);
	for (LatLng entry : addressCache.keySet()) {
		if (LatLngTool.distance(entry, query, LengthUnit.METER) < 30) {
			return addressCache.get(entry);
		}
	}

	// cannot find the place in the cache. Sleep a while and query the
	// OpenStreetMap.
	LoggerFactory.getLogger(this.getClass()).trace("Query {}", query);
	Address newAddress = nominatimClient.getAddress(lng, lat);
	addressCache.put(query, newAddress);
	return newAddress;
}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:17,代码来源:CachedOpenStreetMapClient.java

示例2: getEpisode

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
public ActivityEpisode getEpisode() {
	List<TrackPoint> points = instance.getTrackPoints();
	double distance = 0;
	// compute the distance in mile
	if(points.size() > 0){
		LatLng curLocation = new LatLng(points.get(0).getLat(), points.get(0).getLng());
           DateTime curTime = points.get(0).getTime();
		for (TrackPoint point : points) {
			LatLng nextLocation = new LatLng(point.getLat(), point.getLng());
               DateTime nextTime = point.getTime();
               double displacementInMiles = LatLngTool.distance(curLocation, nextLocation, LengthUnit.MILE);
               double duration = new Duration(curTime, nextTime).getStandardSeconds() / 3600.0;
               double speedInMilesInHours = displacementInMiles / duration;
               // don't count the track points which move too fast to be true...
               if(speedInMilesInHours < 7.0) {
                   distance += displacementInMiles;
               }
               curTime = nextTime;
			curLocation = nextLocation;
		}
	}
	instance.setDistanceInMiles(distance);
	return instance;
}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:25,代码来源:ActivityEpisodeAccumulator.java

示例3: distanceInMeters

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
public double distanceInMeters(Measurement m) {
	double distance = 0;
	if (m != null) {
		/*
		 * double lat1 = this.getLat(); double lat2 = m.getLat(); double
		 * lon1 = this.getLng(); double lon2 = m.getLng(); double dLat =
		 * Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 -
		 * lon1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
		 * Math.cos(Math.toRadians(lat1)) Math.cos(Math.toRadians(lat2)) *
		 * Math.sin(dLon / 2) Math.sin(dLon / 2); double c = 2 *
		 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); distance =
		 * EARTH_RADIUS * c;
		 */
		double lat1 = this.getLat();
		double lat2 = m.getLat();
		double lon1 = this.getLng();
		double lon2 = m.getLng();
		LatLng point1 = new LatLng(lat1, lon1);
		LatLng point2 = new LatLng(lat2, lon2);
		distance = LatLngTool.distance(point1, point2, LengthUnit.METER);
	}
	return distance;
}
 
开发者ID:joluet,项目名称:PreODE,代码行数:24,代码来源:Measurement.java

示例4: getSessionInRange

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
/**
 * Returns a Session from the document store if a session within the range, in meters, exists. Range is determined
 * by calculating the distance between two geopoints, the geopoint of the incoming device, and the geopoint of an
 * existing Session
 *
 * @param   sessions    a list of unlocked/available sessions to check against
 * @param   range       the maximum range from a session for the device to be considered for inclusion
 * @param   j           the JoinMessage object sent by the device that includes its geolocation
 *
 * @return              a session within the desired range, if found
 */
public Session getSessionInRange(List<Session> sessions, float range, JoinMessage j){
    // iterate over the list of sessions and try to find one within proximity of the
    // inbound device. If one is found, create the device to it, and update its Geolocation with the device's
    // geolocation. This way when the next device comes in it will only need to be within proximity
    // to the last device to join the session to be allowed into session
    float[] deviceGeo= j.getGeo();
    LatLng dGeo = new LatLng(new Double(deviceGeo[0]), new Double(deviceGeo[1]));

    for(Session session: sessions){
        float[] sGeo = session.getGeoLocation();
        if(sGeo != null){
            LatLng sessionGeo =new LatLng(new Double(sGeo[0]), new Double(sGeo[1]));
            double distanceFromInboundDevice = LatLngTool.distance(dGeo,sessionGeo, LengthUnit.METER);

            if(distanceFromInboundDevice <= range){
                return session;
            }
        }
    }
    return null;
}
 
开发者ID:wieden-kennedy,项目名称:composite-framework,代码行数:33,代码来源:SessionRepository.java

示例5: calculateDistance

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
public double calculateDistance(GeoCoordinate location1,
		GeoCoordinate location2, SpatialDistanceUnit unit) {
	
	LatLng point1 = new LatLng(location1.getLatitude(), location1.getLongitude());
	LatLng point2 = new LatLng(location2.getLatitude(), location2.getLongitude());
	
	double finalDistance = 0;
	
	if (unit == SpatialDistanceUnit.Meter){
		finalDistance = LatLngTool.distance(point1, point2, LengthUnit.METER);
	}
	else if (unit == SpatialDistanceUnit.Kilometer){
		finalDistance = LatLngTool.distance(point1, point2, LengthUnit.KILOMETER);
	}
	else if (unit == SpatialDistanceUnit.Mile){
		finalDistance = LatLngTool.distance(point1, point2, LengthUnit.MILE);
	}
	else if (unit == SpatialDistanceUnit.NauticalMile){
		finalDistance = LatLngTool.distance(point1, point2, LengthUnit.NAUTICAL_MILE);
	}
	else if (unit == SpatialDistanceUnit.Foot){
		finalDistance = LatLngTool.distance(point1, point2, LengthUnit.METER);
		finalDistance = finalDistance * 3.28084;
	}
	else if (unit == SpatialDistanceUnit.Yard){
		finalDistance = LatLngTool.distance(point1, point2, LengthUnit.METER);
		finalDistance = finalDistance * 1.0936133333333;
	}
	
	return finalDistance;
}
 
开发者ID:hamdikavak,项目名称:human-mobility-modeling-utilities,代码行数:32,代码来源:SpatialOperationHandler.java

示例6: geoDistance

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
private static double geoDistance(double[] geo1, double[] geo2) throws Exception {
	if (geo1[0] == 0 || geo2[0] == 0) { // images with no gps have 0s in the xml file
		return -1000; // unknown distance
	}

	LatLng im1 = new LatLng(geo1[0], geo1[1]);
	LatLng im2 = new LatLng(geo2[0], geo2[1]);

	double distance = LatLngTool.distance(im1, im2, LengthUnit.KILOMETER);
	if (distance < 0) {
		throw new Exception("Negative distance!");
	}
	return distance;
}
 
开发者ID:socialsensor,项目名称:diverse-image-search,代码行数:15,代码来源:Distances.java

示例7: distanceFromLocation

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
/**
 * Calculates and returns the distance (in meters) of this image from the given location.
 * 
 * @return The distance in meters, or -1000 if the location of this image is unknown.
 * @throws Exception
 */
public double distanceFromLocation(double locLat, double locLong) throws Exception {
	if (this.latitude == 0 || this.longitude == 0) { // images with no gps have 0s in the xml file
		// System.out.println("No coordinates for image " + this.getId());
		return -1000; // unknown image location!
	}
	LatLng loc = new LatLng(locLat, locLong);
	LatLng img = new LatLng(latitude, longitude);

	double distance = LatLngTool.distance(loc, img, LengthUnit.METER);
	if (distance < 0) {
		throw new Exception("Negative distance!");
	}
	return distance;
}
 
开发者ID:socialsensor,项目名称:diverse-image-search,代码行数:21,代码来源:MEDI2014Image.java

示例8: computeGeoDistance

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
private void computeGeoDistance(TimeWindow window) {
	// first add all the unprocessed data points to generate the new convex
	// hull
	updateCovexHull();
	List<StreamRecord> hull_points = this.currentConvexHull;
	if (hull_points.size() < 2) {
		// return nothing if we don't have a convex hull...
		return;
	}
	// take distance between the first two points as the initial distance
	StreamRecord earlierPointOnDiameter = null;
	StreamRecord laterPointOnDiameter = null;
	double longestDistanceInHull = 0;
	// compute the pairwise distance between each pair of vertexes to find
	// the
	// longest distance
	for (int i = 0; i < hull_points.size() - 1; i++) {
		for (int j = i + 1; j < hull_points.size(); j++) {
			GeoLocation x = hull_points.get(i).getLocation();
			GeoLocation y = hull_points.get(j).getLocation();
			// compute the diameter in miles
			double distance = GeoLocation.distance(x, y, LengthUnit.MILE);
			if (longestDistanceInHull <= distance) {
				// record the points that have the longest distance so far
				longestDistanceInHull = distance;
				earlierPointOnDiameter = hull_points.get(i);
				laterPointOnDiameter = hull_points.get(j);
			}
		}
	}
	// create the output data
	GeoDiameterData data = new GeoDiameterData(window, this)
			.setDiameter(longestDistanceInHull)
			.setEarlierPointOnDiameter(earlierPointOnDiameter.getLocation())
			.setLaterPointOnDiameter(laterPointOnDiameter.getLocation());
	// emit data
	this.createRecord().setData(data)
			.setTimestamp(window.getFirstInstant()).emit();

}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:41,代码来源:GeoDiameterTask.java

示例9: getDiameter

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
public static double getDiameter(List<StreamRecord> points, LengthUnit unit){
	double maxDist = 0;
	for(int i=0; i<points.size(); i++){
		for(int j=i+1; j<points.size(); j++){
			LatLng l1 = points.get(i).getLocation().getCoordinates();
			LatLng l2 = points.get(j).getLocation().getCoordinates();
			double dist = LatLngTool.distance(l1, l2, unit);
			maxDist = dist > maxDist ? dist : maxDist;
		}	
	}
	return maxDist;
}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:13,代码来源:ConvexHull.java

示例10: resolveLocation

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
public Location resolveLocation(Map<String,Object> tweet) {
	LatLng givenLatLong = Utils.getLatLngFromTweet(tweet);
	
	if (givenLatLong == null)
		return null;
	
	Set<Location> locations = this.getPossibleLocations(givenLatLong);
	Location closestLocation = null;
	double closestDistance = 0;
	
	
	for (Location location : locations) {
		// Check the distance to this location.
		LatLng latLong = location.getLatLng();
		
		double distanceInMiles = LatLngTool.distance(givenLatLong, latLong, LengthUnit.MILE);
		if (closestLocation == null | closestDistance > distanceInMiles) {
			closestDistance = distanceInMiles;
			closestLocation = location;
		}
	}
	
	if (closestLocation != null && closestDistance < this.maxDistance) {
		return closestLocation;
	}
	return null;
}
 
开发者ID:mdredze,项目名称:carmen,代码行数:28,代码来源:GeocodeLocationResolver.java

示例11: executeDataPoint

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
@Override	
public void executeDataPoint(StreamRecord<MobilityData> newRec) {
	if(newRec.getLocation() == null){
		// don't include the data point if it does not have location info
		return;
	}else if(data.size() > 0){
		 // skip out-of-order records
		DateTime lastTime = data.getLast().getLocation().getTimestamp();
		DateTime newTime = newRec.getLocation().getTimestamp();
		if(lastTime.isAfter(newTime)){
			 return;
		}
	}
	data.add(newRec);
	long curMillis = newRec.getLocation().getTimestamp().getMillis();

	// determine the head record's Place/Move state if we have received
	// all the records within the next 10 minutes from its timestamp
	for (long headMillis = getHeadMillis(); curMillis - headMillis > TEN_MINS; headMillis = getHeadMillis()) {
		// get head record
		StreamRecord<MobilityData> headRec = data.removeFirst();

		// compute the max displacement from the head data point to its subsequent data points within the next 10 minutes
		LatLng firstLatLng = headRec.getLocation().getCoordinates();
		Iterator<StreamRecord<MobilityData>> iter = data.iterator();
		double maxDisplacement = -1;
		while (iter.hasNext()) {
			StreamRecord<MobilityData> next = iter.next();
			long nextMillis = next.getLocation().getTimestamp().getMillis();
			// check if the next rec is within the next 10 mins 
			if ((nextMillis - headMillis) > TEN_MINS) {
				break;
			}
			LatLng nextLatLng = next.getLocation().getCoordinates();

			double maxDiff = Math.max(Math.abs(nextLatLng.getLatitude() - firstLatLng.getLatitude()) , 
									  Math.abs(nextLatLng.getLongitude() - firstLatLng.getLongitude())); 
			double displacement;
			if(maxDiff > 0.0001){
				displacement = LatLngTool.distance(firstLatLng, nextLatLng, LengthUnit.METER);
			}else{
				displacement = 0;
			}
			maxDisplacement = Math.max(displacement, maxDisplacement);
		}
		// determine state based on 1) previous state 2) Mobility and 3)
		// displacements
		State curState;
		if (maxDisplacement >= 0) {
			if (headRec.getData().getMode().isActive() && maxDisplacement > 100.0){
				// if it walking or running
				curState = State.Moves;
			} else if (maxDisplacement > 2000.0) {
				// probably transportation
				curState = State.Moves;
			} else if (maxDisplacement < 50) {
				// must be still in a place
				curState = State.Place;
			}else{
				// use the prev state is no idea
				curState = prevState;
			}
		}else{
			// use the prev state if no data point in the next 10 mins
			curState = prevState;
		}
		
		accumulateNewDataPoint(headRec, curState);
	}
}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:71,代码来源:PlaceDetection.java

示例12: distance

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
public static double distance(GeoLocation x, GeoLocation y, LengthUnit unit){
	return LatLngTool.distance(x.coordinates, y.coordinates, unit);
}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:4,代码来源:GeoLocation.java

示例13: call

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
@Override
public Double call() throws Exception {
	Predictor predictor = new Predictor(mModel);
	Measurement[] samples = new Measurement[mMeasurements.length - 1];
	for (int i = 0; i < samples.length; i++) {
		samples[i] = mMeasurements[i];
	}
	Prediction pre = predictor.predict(samples, searchRadius, searchSegmentDistance, accuracyRadius,
			predictionSegments, UTMZoneNo, UTMZoneLetter);

	if (pre == null) {
		System.out.println("Prediction was not possible. Too few data available.");
		return null;
	}

	LatLng predictionPoint = new LatLng(pre.latitude, pre.longitude);

	LatLng[] samplePoints = new LatLng[mMeasurements.length];
	for (int i = 0; i < samplePoints.length; i++) {
		samplePoints[i] = new LatLng(mMeasurements[i].getLat(), mMeasurements[i].getLng());
	}
	double[] distances = new double[samplePoints.length];
	for (int i = 0; i < distances.length - 1; i++) {
		distances[i] = LatLngTool.distance(samplePoints[i], samplePoints[i + 1], LengthUnit.METER);
	}
	distances[distances.length - 1] = LatLngTool.distance(samplePoints[samplePoints.length - 1], predictionPoint,
			LengthUnit.METER);
	double relDist = distances[distances.length - 1] / distances[distances.length - 2];

	String coordianteString = "";
	for (int i = 0; i < mMeasurements.length; i++) {
		coordianteString = coordianteString + mMeasurements[i].getLat() + " " + mMeasurements[i].getLng() + " | ";
	}
	coordianteString = coordianteString + pre.latitude + " " + pre.longitude;

	String distanceString = "";
	for (int i = 0; i < distances.length; i++) {
		distanceString = distanceString + distances[i] + " ";
	}

	String probString = relDist + " " + pre.marginalProbability + " " + pre.probability + " "
			+ pre.widerProbability;
	System.out.println(coordianteString + "\n" + distanceString + "\n" + probString + "\n");

	return distances[distances.length - 1];
}
 
开发者ID:joluet,项目名称:PreODE,代码行数:47,代码来源:PredictionWorker.java

示例14: calculateDistance

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
public static Double calculateDistance(com.javadocmd.simplelatlng.LatLng point1, com.javadocmd.simplelatlng.LatLng point2) {
	return LatLngTool.distance(point1, point2, LengthUnit.KILOMETER);
}
 
开发者ID:thiagoandrade6,项目名称:pubanywhere,代码行数:4,代码来源:GeocoderUtils.java

示例15: travel

import com.javadocmd.simplelatlng.util.LengthUnit; //导入依赖的package包/类
/**
 * <p>
 * Calculate the end point of traveling along a great-circle path from a
 * given starting point with a given intitial bearing for a known distance.
 * </p>
 * 
 * @param start
 *            the starting point.
 * @param initialBearing
 *            the initial bearing.
 * @param distance
 *            the distance to travel.
 * @param unit
 *            the unit in which distance is measured.
 * @return the end point.
 */
public static LatLng travel(LatLng start, double initialBearing,
        double distance, LengthUnit unit) {
    double bR = Math.toRadians(initialBearing);
    double lat1R = Math.toRadians(start.getLatitude());
    double lon1R = Math.toRadians(start.getLongitude());
    double dR = distance / LatLngConfig.getEarthRadius(unit);

    double a = Math.sin(dR) * Math.cos(lat1R);
    double lat2 = Math.asin(Math.sin(lat1R) * Math.cos(dR) + a
            * Math.cos(bR));
    double lon2 = lon1R
            + Math.atan2(Math.sin(bR) * a, Math.cos(dR) - Math.sin(lat1R)
                    * Math.sin(lat2));
    return new LatLng(Math.toDegrees(lat2), Math.toDegrees(lon2));
}
 
开发者ID:wangbai,项目名称:simplelatlng,代码行数:32,代码来源:LatLngTool.java


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