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


Java LatLng类代码示例

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


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

示例1: getAddress

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

import com.javadocmd.simplelatlng.LatLng; //导入依赖的package包/类
@Override
public GeoLocation deserialize(JsonParser jp,
		DeserializationContext ctxt) throws
              IOException {
	ObjectCodec oc = jp.getCodec();
	JsonNode node = oc.readTree(jp);

	LatLng geo = new LatLng(node.get("latitude").asDouble(), node.get(
			"longitude").asDouble());
	DateTime timestamp = null;
	if (node.get("timestamp") != null) {
		timestamp = new DateTime(node.get("timestamp").asText());
	} else if (node.get("time") != null && node.get("timezone") != null) {
		timestamp = new DateTime(node.get("time").asLong(),
				DateTimeZone.forID(node.get("timezone").asText()));
	}
	double accuracy = node.get("accuracy").asDouble();
	String provider = node.get("provider").asText();
	return (new GeoLocation(timestamp, geo, accuracy, provider));
}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:21,代码来源:GeoLocation.java

示例4: distanceInMeters

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

示例5: getSessionInRange

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

示例6: isSimple

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

示例7: RectangularWindow

import com.javadocmd.simplelatlng.LatLng; //导入依赖的package包/类
/**
 * Creates a pseudo-rectangular window. Note: this constructor must not be
 * used with polar coordinates, where the notions of east and west are
 * invalid.
 * 
 * @param northeast
 *            the northeastern corner of this window.
 * @param southwest
 *            the southwestern corner of this window.
 * @throws IllegalArgumentException
 *             if either northeast or southwest are polar coordinates, also
 *             if the northeast point is south of the southwest point.
 */
public RectangularWindow(LatLng northeast, LatLng southwest) {
    if (northeast.isPolar() || southwest.isPolar())
        throw new IllegalArgumentException(
                "Window constructor is not valid for polar coordinates.");
    if (northeast.getLatitudeInternal() < southwest.getLatitudeInternal())
        throw new IllegalArgumentException(
                "Provided northeast point is not north of provided southwest point.");

    double deltaLat = northeast.getLatitude() - southwest.getLatitude();
    double deltaLng = northeast.getLongitude() - southwest.getLongitude();
    if (northeast.getLongitude() < southwest.getLongitude())
        deltaLng += 360;

    double centerLat = southwest.getLatitude() + deltaLat / 2;
    double centerLng = southwest.getLongitude() + deltaLng / 2;

    this.setWindow(new LatLng(centerLat, centerLng), deltaLat, deltaLng);
}
 
开发者ID:wangbai,项目名称:simplelatlng,代码行数:32,代码来源:RectangularWindow.java

示例8: setWindow

import com.javadocmd.simplelatlng.LatLng; //导入依赖的package包/类
/**
 * Sets the bounds of this window.
 * 
 * @param center
 *            the center point.
 * @param deltaLat
 *            the span of the window in latitude in degrees.
 * @param deltaLng
 *            the span of the window in longitude in degrees.
 */
public void setWindow(LatLng center, double deltaLat, double deltaLng) {
    if (center == null)
        throw new IllegalArgumentException("Invalid center point.");
    if (Double.isNaN(deltaLat) || Double.isInfinite(deltaLat))
        throw new IllegalArgumentException("Invalid latitude delta.");
    if (Double.isNaN(deltaLng) || Double.isInfinite(deltaLng))
        throw new IllegalArgumentException("Invalid longitude delta.");

    double dlat = min(abs(deltaLat), 180.0);
    this.setLatWindow(center.getLatitude(), dlat);

    double dlng = min(abs(deltaLng), 360.0);
    this.setLngWindow(center.getLongitude(), dlng);

    this.center = center;
}
 
开发者ID:wangbai,项目名称:simplelatlng,代码行数:27,代码来源:RectangularWindow.java

示例9: contains

import com.javadocmd.simplelatlng.LatLng; //导入依赖的package包/类
@Override
public boolean contains(LatLng point) {

    if (point.getLatitudeInternal() > maxLatitude
            || point.getLatitudeInternal() < minLatitude) {
        return false;
    }

    long longitude = point.getLongitudeInternal();
    if (crosses180thMeridian) {
        if (longitude < 0 && longitude > rightLongitude) {
            return false;
        }
        if (longitude >= 0 && longitude < leftLongitude) {
            return false;
        }
    } else if (longitude > rightLongitude || longitude < leftLongitude) {
        return false;
    }
    return true;
}
 
开发者ID:wangbai,项目名称:simplelatlng,代码行数:22,代码来源:RectangularWindow.java

示例10: getGeolocation

import com.javadocmd.simplelatlng.LatLng; //导入依赖的package包/类
/**
 * Returns a {@link LatLng} object with the geolocation of the vector with the given internal id or null
 * if the internal id does not exist. Accesses the BDB store!
 * 
 * @param iid
 *            The internal id of the vector
 * @return The geolocation mapped to the given internal id or null if the internal id does not exist
 */
public LatLng getGeolocation(int iid) {
	if (iid < 0 || iid > loadCounter) {
		System.out.println("Internal id " + iid + " is out of range!");
		return null;
	}
	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(iid, key);
	DatabaseEntry data = new DatabaseEntry();
	if ((iidToGeolocationDB.get(null, key, data, null) == OperationStatus.SUCCESS)) {
		TupleInput input = TupleBinding.entryToInput(data);
		double latitude = input.readDouble();
		double longitude = input.readDouble();
		LatLng geolocation = new LatLng(latitude, longitude);
		return geolocation;
	} else {
		System.out.println("Internal id " + iid + " is in range but gelocation was not found.");
		return null;
	}
}
 
开发者ID:MKLab-ITI,项目名称:multimedia-indexing,代码行数:28,代码来源:AbstractSearchStructure.java

示例11: getLatLngFromTweet

import com.javadocmd.simplelatlng.LatLng; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static LatLng getLatLngFromTweet(Map<String, Object> tweet) {
	Map<String, Object> coordinates = (Map<String, Object>) tweet.get(Constants.COORDINATES);
	if (coordinates == null)
		return null;
	ArrayList<Object> coordinateList = (ArrayList<Object>) coordinates.get(Constants.COORDINATES);

	double longitude = 0;
	if (coordinateList.get(0) instanceof Double)
		longitude = (Double)coordinateList.get(0);
	else if (coordinateList.get(0) instanceof Integer)
		longitude = (double)(Integer)coordinateList.get(0);
	else
		return null;
	
	double latitude = 0;
	if (coordinateList.get(1) instanceof Double)
		latitude = (Double)coordinateList.get(1);
	else if (coordinateList.get(1) instanceof Integer)
		latitude = (double)(Integer)coordinateList.get(1);
	else
		return null;
	
	LatLng latLng = new LatLng(latitude, longitude);
	return latLng;
}
 
开发者ID:mdredze,项目名称:carmen,代码行数:27,代码来源:Utils.java

示例12: addLocation

import com.javadocmd.simplelatlng.LatLng; //导入依赖的package包/类
public void addLocation(Location location) {
	if (location.getLatLng() == null)
		return;
	
	LatLng latLong = location.getLatLng();
	List<String> keys = this.getKeys(latLong);
	
	for (String key : keys) {
		if (!this.locationMap.containsKey(key)) {
			this.locationMap.put(key, new LinkedList<Location>());
		}
		
		List<Location> locations = this.locationMap.get(key);
		locations.add(location);
	}
}
 
开发者ID:mdredze,项目名称:carmen,代码行数:17,代码来源:GeocodeLocationResolver.java

示例13: getKeys

import com.javadocmd.simplelatlng.LatLng; //导入依赖的package包/类
private List<String> getKeys(LatLng latLong) {
	double latitude = latLong.getLatitude() * 100;
	double longitude = latLong.getLongitude() * 100;
	double shiftSize = this.cellSize  / (double)2;
	
	List<String> keys = new LinkedList<String>();
	
	keys.add(Integer.toString((int) (latitude/this.cellSize)) + "&&" + Integer.toString((int) (longitude/this.cellSize)));
	
	keys.add(Integer.toString((int) (latitude+shiftSize/this.cellSize)) + "&&" + Integer.toString((int) (longitude/this.cellSize)));
	keys.add(Integer.toString((int) (latitude-shiftSize/this.cellSize)) + "&&" + Integer.toString((int) (longitude/this.cellSize)));
	keys.add(Integer.toString((int) (latitude/this.cellSize)) + "&&" + Integer.toString((int) (longitude+shiftSize/this.cellSize)));
	keys.add(Integer.toString((int) (latitude/this.cellSize)) + "&&" + Integer.toString((int) (longitude-shiftSize/this.cellSize)));
	keys.add(Integer.toString((int) (latitude+shiftSize/this.cellSize)) + "&&" + Integer.toString((int) (longitude+shiftSize/this.cellSize)));
	keys.add(Integer.toString((int) (latitude+shiftSize/this.cellSize)) + "&&" + Integer.toString((int) (longitude-shiftSize/this.cellSize)));
	keys.add(Integer.toString((int) (latitude-shiftSize/this.cellSize)) + "&&" + Integer.toString((int) (longitude+shiftSize/this.cellSize)));
	keys.add(Integer.toString((int) (latitude-shiftSize/this.cellSize)) + "&&" + Integer.toString((int) (longitude-shiftSize/this.cellSize)));
			
	return keys;
}
 
开发者ID:mdredze,项目名称:carmen,代码行数:21,代码来源:GeocodeLocationResolver.java

示例14: calculateDistance

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

示例15: geoDistance

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


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