/** * Returns whether this contains the given {@link LatLng}. * * @param point the {@link LatLng} to test * @return {@code true} if this contains the given point; {@code false} if not. */ public boolean contains(LatLng point) { return containsLatitude(point.latitude) && containsLongitude(point.longitude); }
/** * Returns a new {@link LatLngBounds} that extends this {@link LatLngBounds} to include the * given {@link LatLng}. This will return the smallest LatLngBounds that contains both this * and the extra point. * <p/> * In particular, it will consider extending the bounds both in the eastward and westward * directions (one of which may cross the antimeridian) and choose the smaller of the two. In * the case that both directions result in a LatLngBounds of the same size, this will extend * it in the eastward direction. * * @param point a {@link LatLng} to be included in the new bounds * @return A new {@link LatLngBounds} that contains this and the extra point. */ public LatLngBounds including(LatLng point) { double latMin = Math.min(southwest.latitude, point.latitude); double latMax = Math.max(northeast.latitude, point.latitude); double lonMin = southwest.longitude; double lonMax = northeast.longitude; if (!containsLongitude(point.longitude)) { if ((southwest.longitude - point.longitude + 360.0) % 360.0 < (point.longitude - northeast.longitude + 360.0D) % 360.0D) { lonMin = point.longitude; } else { lonMax = point.longitude; } } return new LatLngBounds(new LatLng(latMin, lonMin), new LatLng(latMax, lonMax)); }