/** * Given a set of four latLng coordinates, creates a LatLng Bound * * @param north North coordinate of the bounding box * @param south South coordinate of the bounding box * @param east East coordinate of the bounding box * @param west West coordinate of the bounding box */ private static LatLngBounds createLatLngBounds(Double north, Double south, Double east, Double west) { LatLng southWest = new LatLng(south, west); LatLng northEast = new LatLng(north, east); return new LatLngBounds(southWest, northEast); } }
@Override public void getMapScreenBounds(OnMapBoundsCallback callback) { final Projection projection = googleMap.getProjection(); int hOffset = getResources().getDimensionPixelOffset(R.dimen.map_horizontal_padding); int vOffset = getResources().getDimensionPixelOffset(R.dimen.map_vertical_padding); LatLngBounds.Builder builder = LatLngBounds.builder(); builder.include(projection.fromScreenLocation(new Point(hOffset, vOffset))); // top-left builder.include(projection.fromScreenLocation( new Point(getView().getWidth() - hOffset, vOffset))); // top-right builder.include(projection.fromScreenLocation( new Point(hOffset, getView().getHeight() - vOffset))); // bottom-left builder.include(projection.fromScreenLocation(new Point(getView().getWidth() - hOffset, getView().getHeight() - vOffset))); // bottom-right callback.onMapBoundsReady(builder.build()); }
/** * Includes this point for building of the bounds. The bounds will be extended in a * minimum way to include this point. * <p/> * More precisely, 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. For example, adding points (0, -179) and (1, 179) * will create a bound crossing the 180 longitude. * * @param point A {@link LatLng} to be included in the bounds. * @return This builder object with a new point added. */ public Builder include(LatLng point) { if (bounds == null) { bounds = new LatLngBounds(point, point); } else { bounds = bounds.including(point); } return this; } }
/** * 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)); }
private void addMarker(DelegatingMarker marker) { if (visibleRegionBounds.contains(marker.getPosition())) { marker.changeVisible(true); } else { markers.add(marker); } } }
@Override public void onPositionChange(DelegatingMarker marker) { if (!marker.isVisible()) { return; } if (markers.contains(marker)) { if (visibleRegionBounds.contains(marker.getPosition())) { markers.remove(marker); marker.changeVisible(true); } } }
@JavascriptInterface public void getBoundsCallback( double neLat, double neLng, double swLat, double swLng) { final LatLngBounds bounds = new LatLngBounds(new LatLng(swLat, swLng), new LatLng(neLat, neLng)); handler.post(new Runnable() { @Override public void run() { onMapBoundsCallback.onMapBoundsReady(bounds); } }); }
@Override public boolean onClusterClick(Cluster<Person> cluster) { // Show a toast with some info when the cluster is clicked. String firstName = cluster.getItems().iterator().next().name; Toast.makeText(this, cluster.getSize() + " (including " + firstName + ")", Toast.LENGTH_SHORT).show(); // Zoom in the cluster. Need to create LatLngBounds and including all the cluster items // inside of bounds, then animate to center of the bounds. // Create the builder to collect all essential cluster items for the bounds. LatLngBounds.Builder builder = LatLngBounds.builder(); for (ClusterItem item : cluster.getItems()) { builder.include(item.getPosition()); } // Get the LatLngBounds final LatLngBounds bounds = builder.build(); // Animate camera to the bounds try { getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100)); } catch (Exception e) { e.printStackTrace(); } return true; }
private boolean showDefaultIcon(final Network network) { final boolean showLabel = prefs.getBoolean( ListFragment.PREF_MAP_LABEL, true ); if (showLabel) { final LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds; // if on screen, and room in labeled networks, we can show the label if (bounds.contains(network.getLatLng()) && MapRender.this.labeledNetworks.size() <= MAX_LABELS) { return false; } } return true; }
/** * Parses a bounding box given as a JSONArray of 4 elements in the order of lowest values for * all axes followed by highest values. Axes order of a bounding box follows the axes order of * geometries. * * @param coordinates array of 4 coordinates * @return LatLngBounds containing the coordinates of the bounding box * @throws JSONException if the bounding box could not be parsed */ private static LatLngBounds parseBoundingBox(JSONArray coordinates) throws JSONException { // Lowest values for all axes LatLng southWestCorner = new LatLng(coordinates.getDouble(1), coordinates.getDouble(0)); // Highest value for all axes LatLng northEastCorner = new LatLng(coordinates.getDouble(3), coordinates.getDouble(2)); return new LatLngBounds(southWestCorner, northEastCorner); }
/** * Move the camera to show all of Australia. * Construct a {@link com.google.android.gms.maps.model.LatLngBounds} from markers positions, * then move the camera. */ public void showAustralia(View v) { // Wait until map is ready if (mMap == null) { return; } // Create bounds that include all locations of the map LatLngBounds.Builder boundsBuilder = LatLngBounds.builder() .include(PERTH) .include(ADELAIDE) .include(MELBOURNE) .include(SYDNEY) .include(DARWIN) .include(BRISBANE); // Move camera to show all markers and locations mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(boundsBuilder.build(), 20)); }
private void showMarkersInVisibleRegion() { IProjection projection = map.getProjection(); VisibleRegion visibleRegion = projection.getVisibleRegion(); visibleRegionBounds = visibleRegion.latLngBounds; Iterator<DelegatingMarker> iterator = markers.iterator(); while (iterator.hasNext()) { DelegatingMarker marker = iterator.next(); if (visibleRegionBounds.contains(marker.getPosition())) { marker.changeVisible(true); iterator.remove(); } } }
public void testGetBoundingBox() throws Exception { assertEquals(new LatLngBounds(new LatLng(-80, -150), new LatLng(80, 150)), mLayer.getBoundingBox()); }
public void zoomToTwoPoints(LatLng pointA, LatLng pointB) { if ((pointA.latitude != pointB.latitude) && (pointA.longitude != pointB.longitude)) { LatLngBounds.Builder boundsCreator = LatLngBounds.builder(); boundsCreator.include(pointA); boundsCreator.include(pointB); mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(boundsCreator.build(), getResources().getInteger(R.integer.route_zoom_padding))); } }
@Override protected Void doInBackground(LatLngBounds... bounds) { final Collection<Network> nets = MainActivity.getNetworkCache().values(); for (final Network network : nets) { final Marker marker = NetworkRenderer.this.getMarker(network); if (marker != null && network.getLatLng() != null) { final boolean inBounds = bounds[0].contains(network.getLatLng()); if (inBounds || MapRender.this.labeledNetworks.contains(network)) { // MainActivity.info("sendupdate: " + network.getBssid()); sendUpdateNetwork(network.getBssid()); } } } return null; }
public void testGetBoundingBox() { feature = new GeoJsonFeature(null, null, null, null); assertNull(feature.getBoundingBox()); LatLngBounds boundingBox = new LatLngBounds(new LatLng(-20, -20), new LatLng(50, 50)); feature = new GeoJsonFeature(null, null, null, boundingBox); assertEquals(boundingBox, feature.getBoundingBox()); }
public static LatLngBounds fromCenterAndPositions(LatLng center, Iterable<LatLng> positions) { LatLngBounds.Builder builder = LatLngBounds.builder(); builder.include(center); for (LatLng position : positions) { LatLng other = new LatLng(2 * center.latitude - position.latitude, 2 * center.longitude - position.longitude); builder.include(position); builder.include(other); } return builder.build(); }
@Override public com.google.android.gms.maps.model.LatLngBounds map(LatLngBounds input) { LatLng southWest = AnyMapAdapter.adapt(input.southwest); LatLng northEast = AnyMapAdapter.adapt(input.northeast); return new com.google.android.gms.maps.model.LatLngBounds(southWest, northEast); }