@Override public int hashCode() { int result = status != null ? status.hashCode() : 0; result = 31 * result + (int) (inReplyToStatusId ^ inReplyToStatusId >>> 32); result = 31 * result + (location != null ? location.hashCode() : 0); result = 31 * result + (placeId != null ? placeId.hashCode() : 0); result = 31 * result + (displayCoordinates ? 1 : 0); result = 31 * result + (possiblySensitive ? 1 : 0); result = 31 * result + (mediaName != null ? mediaName.hashCode() : 0); result = 31 * result + (mediaBody != null ? mediaBody.hashCode() : 0); result = 31 * result + (mediaFile != null ? mediaFile.hashCode() : 0); return result; }
@Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final StatusUpdate that = (StatusUpdate) o; if (displayCoordinates != that.displayCoordinates) return false; if (inReplyToStatusId != that.inReplyToStatusId) return false; if (possiblySensitive != that.possiblySensitive) return false; if (location != null ? !location.equals(that.location) : that.location != null) return false; if (mediaBody != null ? !mediaBody.equals(that.mediaBody) : that.mediaBody != null) return false; if (mediaFile != null ? !mediaFile.equals(that.mediaFile) : that.mediaFile != null) return false; if (mediaName != null ? !mediaName.equals(that.mediaName) : that.mediaName != null) return false; if (placeId != null ? !placeId.equals(that.placeId) : that.placeId != null) return false; if (status != null ? !status.equals(that.status) : that.status != null) return false; return true; }
/* package */ HttpParameter[] asHttpParameterArray(final HttpParameter includeEntities) { final ArrayList<HttpParameter> params = new ArrayList<HttpParameter>(); appendParameter("status", status, params); if (-1 != inReplyToStatusId) { appendParameter("in_reply_to_status_id", inReplyToStatusId, params); } if (location != null) { appendParameter("lat", location.getLatitude(), params); appendParameter("long", location.getLongitude(), params); } appendParameter("place_id", placeId, params); if (!displayCoordinates) { appendParameter("display_coordinates", "false", params); } params.add(includeEntities); if (null != mediaFile) { Log.v("StatusUpdate", "null != mediaFile"); params.add(new HttpParameter("media[]", mediaFile)); params.add(new HttpParameter("possibly_sensitive", possiblySensitive)); } else if (mediaName != null && mediaBody != null) { Log.v("StatusUpdate", "mediaName != null && mediaBody != null"); params.add(new HttpParameter("media[]", mediaName, mediaBody)); params.add(new HttpParameter("possibly_sensitive", possiblySensitive)); } final HttpParameter[] paramArray = new HttpParameter[params.size()]; for (HttpParameter param : params) { Log.v("StatusUpdate", "name " + param.getName()); Log.v("StatusUpdate", "name " + param.getValue()); } return params.toArray(paramArray); }
@Override public boolean equals(Object obj) { GeoLocation aux = (GeoLocation) obj; return latitude == aux.getLatitude() && longitude == aux.getLongitude(); }
private Tweet getTweetObjectFromStatus(Status status) { Tweet tweet = new Tweet(); tweet.setId(Long.toString(status.getId())); tweet.setText(status.getText()); tweet.setCreatedAt(status.getCreatedAt()); tweet.setFavCount(status.getFavoriteCount()); User user = status.getUser(); tweet.setUserId(user.getId()); tweet.setUserName(user.getName()); tweet.setUserScreenName(user.getScreenName()); HashtagEntity[] hashtagEntities = status.getHashtagEntities(); List<String> hashtags = new ArrayList<String>(); for (HashtagEntity hashtagEntity : hashtagEntities) { hashtags.add(hashtagEntity.getText()); } tweet.setHashTags(hashtags.toArray(new String[hashtags.size()])); GeoLocation geoLocation = status.getGeoLocation(); if (geoLocation != null) { double[] coordinates = {geoLocation.getLongitude(), geoLocation.getLatitude()}; tweet.setCoordinates(coordinates); } return tweet; }
/** * @param radius radius of the sphere. * @param location center of the query circle. * @param distance radius of the query circle. * @param connection an SQL connection. * @return places within the specified distance from location. */ public static java.sql.ResultSet findPlacesWithinDistance( double radius, GeoLocation location, double distance, java.sql.Connection connection) throws java.sql.SQLException { GeoLocation[] boundingCoordinates = location.boundingCoordinates(distance, radius); boolean meridian180WithinDistance = boundingCoordinates[0].getLongitudeInRadians() > boundingCoordinates[1].getLongitudeInRadians(); java.sql.PreparedStatement statement = connection.prepareStatement( "SELECT * FROM Places WHERE (Lat >= ? AND Lat <= ?) AND (Lon >= ? " + (meridian180WithinDistance ? "OR" : "AND") + " Lon <= ?) AND " + "acos(sin(?) * sin(Lat) + cos(?) * cos(Lat) * cos(Lon - ?)) <= ?"); statement.setDouble(1, boundingCoordinates[0].getLatitudeInRadians()); statement.setDouble(2, boundingCoordinates[1].getLatitudeInRadians()); statement.setDouble(3, boundingCoordinates[0].getLongitudeInRadians()); statement.setDouble(4, boundingCoordinates[1].getLongitudeInRadians()); statement.setDouble(5, location.getLatitudeInRadians()); statement.setDouble(6, location.getLatitudeInRadians()); statement.setDouble(7, location.getLongitudeInRadians()); statement.setDouble(8, distance / radius); return statement.executeQuery(); }
private static List<List<List<Double>>> getPlaceCoordinates(GeoLocation[][] geoLocations) { List<List<List<Double>>> listListListBoundingBox = new ArrayList<>(); for (GeoLocation[] geoLocation1 : geoLocations) { List<List<Double>> listListBoundingBox = new ArrayList<>(); for (GeoLocation geoLocation2 : geoLocation1) { List<Double> listBoundingBox = new ArrayList<>(); listBoundingBox.add(geoLocation2.getLatitude()); listBoundingBox.add(geoLocation2.getLongitude()); listListBoundingBox.add(listBoundingBox); } listListListBoundingBox.add(listListBoundingBox); } return listListListBoundingBox; }
@SuppressWarnings("unused") public static void main(String[] args) { double earthRadius = 6371.01; GeoLocation myLocation = GeoLocation.fromRadians(1.3963, -0.6981); double distance = 1000; // java.sql.Connection connection = ...; // // java.sql.ResultSet resultSet = findPlacesWithinDistance( // earthRadius, myLocation, distance, connection); // // ...; }
/** * @param latitude the latitude, in radians. * @param longitude the longitude, in radians. */ public static GeoLocation fromRadians(double latitude, double longitude) { GeoLocation result = new GeoLocation(); result.radLat = latitude; result.radLon = longitude; result.degLat = Math.toDegrees(latitude); result.degLon = Math.toDegrees(longitude); result.checkBounds(); return result; }
public static GeoLocation getLocation(InetAddress ipAddress) { return GeoLocation.map(lookUp.getLocation(ipAddress)); }
public static GeoLocation getLocation(String ipAddress) { return GeoLocation.map(lookUp.getLocation(ipAddress)); }
/** * @param inputFile * @return true if the file was read and parsed properly, false otherwise */ public boolean read(File inputFile) { KMLParser parser = new KMLParser(); Configuration.properties.setProperty(Configuration.GENERATE_IDS, Configuration.OFF); Kml kml; GeoLocation topRight = null; GeoLocation bottomLeft = null; try { kml = parser.parse(inputFile); Document d = kml.getDocument(); Feature[] features = d.getFeatures(); mPoly = new ArrayList<MyPolygon>(features.length); for (Feature f : features) { Placemark p = (Placemark) f; double[] coords = p.getPolygon().getOuterBoundaryIs().getLinearRing().getNumericalCoordinates(); MyPolygon poly = new MyPolygon(); ArrayList<GeoLocation> polyPoints = new ArrayList<GeoLocation>(Math.round((float) coords.length * 0.666666f)); for (int i = 0; i < coords.length; i = i + 3) { GeoLocation dp = new GeoLocation(); dp.lon = coords[i]; dp.lat = coords[i + 1]; if (topRight == null) { topRight = new GeoLocation(dp.lat, dp.lon); bottomLeft = new GeoLocation(dp.lat, dp.lon); } if (dp.lat > topRight.lat) topRight.lat = dp.lat; if (dp.lat < bottomLeft.lat) bottomLeft.lat = dp.lat; if (dp.lon > topRight.lon) topRight.lon = dp.lon; if (dp.lon < bottomLeft.lon) bottomLeft.lon = dp.lon; polyPoints.add(dp); } poly.mLocations = polyPoints; mPoly.add(poly); } } catch (IOException e) { e.printStackTrace(); return false; } catch (SAXException e) { e.printStackTrace(); return false; } double margin = .5d; // Add Horiz Margins bottomLeft.lon -= margin; topRight.lon += margin; // Add Vert margins bottomLeft.lat -= margin; topRight.lat += margin; mTopRight = topRight; mBottomLeft = bottomLeft; return true; }
public void setNear(GeoLocation location) { put("near", location.getLatitude() + "," + location.getLongitude()); }
public Double getLongitude() { return location.getLongitude(); }