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


Java LatLngTool类代码示例

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


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

示例1: getAddress

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的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.LatLngTool; //导入依赖的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.LatLngTool; //导入依赖的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.LatLngTool; //导入依赖的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: isSimple

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的package包/类
public static boolean isSimple(LatLng[] points) {
    int total = points.length;
    for (int i = 0; i < total; ++i) {
        LatLng Pa1 = points[i];
        LatLng Pa2 = points[(i + 1) % total];

        for (int j = 1; j < total - 2; ++j) {
            int k = i + j + 1;
            LatLng Pb1 = points[k % total];
            LatLng Pb2 = points[(k + 1) % total];

            // if there are two bounds intersected,
            // it is not a simple polygon
            if (LatLngTool.isIntersected(Pa1, Pa2, Pb1, Pb2)) {
                return false;
            }
        }
    }

    return true;
}
 
开发者ID:wangbai,项目名称:simplelatlng,代码行数:22,代码来源:PolygonWindow.java

示例6: setLngWindow

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的package包/类
/**
 * Fixes and sets the longitude parameters for the window.
 */
private void setLngWindow(double centerLng, double deltaLng) {
    double left = centerLng - (deltaLng / 2.0);
    double right = centerLng + (deltaLng / 2.0);
    if (LatLngConfig.doubleToLong(right) > 180000000l
            || LatLngConfig.doubleToLong(left) < -180000000l) {
        this.crosses180thMeridian = true;
    } else {
        this.crosses180thMeridian = false;
    }
    left = LatLngTool.normalizeLongitude(left);
    right = LatLngTool.normalizeLongitude(right);
    this.leftLongitude = LatLngConfig.doubleToLong(left);
    this.rightLongitude = LatLngConfig.doubleToLong(right);
    this.longitudeDelta = LatLngConfig.doubleToLong(deltaLng);
}
 
开发者ID:wangbai,项目名称:simplelatlng,代码行数:19,代码来源:RectangularWindow.java

示例7: calculateDistance

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的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

示例8: geoDistance

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的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

示例9: distanceFromLocation

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的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

示例10: getDiameter

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的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

示例11: containsForSort

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的package包/类
/**
 * A specialized implementation of the {@link #contains(LatLng)} check which
 * returns the distance from the center of the window if the window contains
 * the point and null if it does not. Used in
 * {@link #filterCopySort(Collection, Collection, FilterHelper)}.
 */
private Double containsForSort(LatLng point) {
    double d = Math.toDegrees(LatLngTool.distanceInRadians(center, point));
    if (LatLngConfig.doubleToLong(d) <= radius)
        return d;
    else
        return null;
}
 
开发者ID:wangbai,项目名称:simplelatlng,代码行数:14,代码来源:CircularWindow.java

示例12: setLatWindow

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的package包/类
/**
 * Fixes and sets the latitude parameters for the window.
 */
private void setLatWindow(double centerLat, double deltaLat) {
    double lat1 = LatLngTool
            .normalizeLatitude(centerLat + (deltaLat / 2.0));
    double lat2 = LatLngTool
            .normalizeLatitude(centerLat - (deltaLat / 2.0));
    this.maxLatitude = LatLngConfig.doubleToLong(Math.max(lat1, lat2));
    this.minLatitude = LatLngConfig.doubleToLong(Math.min(lat1, lat2));
    this.latitudeDelta = LatLngConfig.doubleToLong(deltaLat);
}
 
开发者ID:wangbai,项目名称:simplelatlng,代码行数:13,代码来源:RectangularWindow.java

示例13: resolveLocation

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的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

示例14: executeDataPoint

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的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

示例15: distance

import com.javadocmd.simplelatlng.LatLngTool; //导入依赖的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


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