com.google.android.gms.maps.model.LatLngBounds Java Examples
The following examples show how to use
com.google.android.gms.maps.model.LatLngBounds.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java From roads-api-samples with Apache License 2.0 | 6 votes |
@Override protected void onPostExecute(List<SnappedPoint> snappedPoints) { mSnappedPoints = snappedPoints; mProgressBar.setVisibility(View.INVISIBLE); findViewById(R.id.speed_limits).setEnabled(true); com.google.android.gms.maps.model.LatLng[] mapPoints = new com.google.android.gms.maps.model.LatLng[mSnappedPoints.size()]; int i = 0; LatLngBounds.Builder bounds = new LatLngBounds.Builder(); for (SnappedPoint point : mSnappedPoints) { mapPoints[i] = new com.google.android.gms.maps.model.LatLng(point.location.lat, point.location.lng); bounds.include(mapPoints[i]); i += 1; } mMap.addPolyline(new PolylineOptions().add(mapPoints).color(Color.BLUE)); mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), 0)); }
Example #2
Source File: LiteDemoActivity.java From android-samples with Apache License 2.0 | 6 votes |
/** * 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 (map == 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 map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundsBuilder.build(), 20)); }
Example #3
Source File: MovingMarkerActivity.java From Airbnb-Android-Google-Map-View with MIT License | 6 votes |
@Override public void onMapReady(GoogleMap googleMap) { mGoogleMap = googleMap; if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } mGoogleMap.setMyLocationEnabled(true); mGoogleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition position) { LatLngBounds bounds = mGoogleMap.getProjection().getVisibleRegion().latLngBounds; mAdapter.setBounds(bounds); } }); }
Example #4
Source File: MapUtils.java From geopackage-android-map with MIT License | 6 votes |
/** * Get the WGS84 bounding box of the current map view screen. * The max longitude will be larger than the min resulting in values larger than 180.0. * * @param map google map * @return current bounding box */ public static BoundingBox getBoundingBox(GoogleMap map) { LatLngBounds visibleBounds = map.getProjection() .getVisibleRegion().latLngBounds; LatLng southwest = visibleBounds.southwest; LatLng northeast = visibleBounds.northeast; double minLatitude = southwest.latitude; double maxLatitude = northeast.latitude; double minLongitude = southwest.longitude; double maxLongitude = northeast.longitude; if (maxLongitude < minLongitude) { maxLongitude += (2 * ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH); } BoundingBox boundingBox = new BoundingBox(minLongitude, minLatitude, maxLongitude, maxLatitude); return boundingBox; }
Example #5
Source File: RiderMapPresenter.java From ridesharing-android with MIT License | 6 votes |
private void updateMapCamera() { if (mState.pickupPlace != null && mState.dropOffPlace != null) { LatLngBounds.Builder builder = new LatLngBounds.Builder(); if (mState.currentLocation != null) { builder.include(new LatLng(mState.currentLocation.getLatitude(), mState.currentLocation.getLongitude())); } builder.include(mState.pickupPlace.getLatLng()); builder.include(mState.dropOffPlace.getLatLng()); animateCamera(builder.build()); } else { if (mState.pickupPlace != null) { animateCamera(mState.pickupPlace.getLatLng()); } else if (mState.dropOffPlace != null) { animateCamera(mState.dropOffPlace.getLatLng()); } } }
Example #6
Source File: GeoJsonParser.java From ground-android with Apache License 2.0 | 6 votes |
/** * Returns the immutable list of tiles specified in {@param geojson} that intersect {@param * bounds}. */ public ImmutableList<Tile> intersectingTiles(LatLngBounds bounds, File file) { try { String fileContents = FileUtils.readFileToString(file, Charset.forName(JSON_SOURCE_CHARSET)); // TODO: Separate parsing and intersection checks, make asyc (single, completable). JSONObject geoJson = new JSONObject(fileContents); // TODO: Make features constant. JSONArray features = geoJson.getJSONArray(FEATURES_KEY); return stream(toArrayList(features)) .map(GeoJsonTile::new) .filter(tile -> tile.boundsIntersect(bounds)) .map(this::jsonToTile) .collect(toImmutableList()); } catch (JSONException | IOException e) { Log.e(TAG, "Unable to parse JSON", e); } return ImmutableList.of(); }
Example #7
Source File: GeoJsonParser.java From android-maps-utils with Apache License 2.0 | 6 votes |
/** * Parses a single GeoJSON feature which contains a geometry and properties member both of * which can be null. Also parses the bounding box and id members of the feature if they exist. * * @param geoJsonFeature feature to parse * @return GeoJsonFeature object */ private static GeoJsonFeature parseFeature(JSONObject geoJsonFeature) { String id = null; LatLngBounds boundingBox = null; Geometry geometry = null; HashMap<String, String> properties = new HashMap<String, String>(); try { if (geoJsonFeature.has(FEATURE_ID)) { id = geoJsonFeature.getString(FEATURE_ID); } if (geoJsonFeature.has(BOUNDING_BOX)) { boundingBox = parseBoundingBox(geoJsonFeature.getJSONArray(BOUNDING_BOX)); } if (geoJsonFeature.has(FEATURE_GEOMETRY) && !geoJsonFeature.isNull(FEATURE_GEOMETRY)) { geometry = parseGeometry(geoJsonFeature.getJSONObject(FEATURE_GEOMETRY)); } if (geoJsonFeature.has(PROPERTIES) && !geoJsonFeature.isNull(PROPERTIES)) { properties = parseProperties(geoJsonFeature.getJSONObject("properties")); } } catch (JSONException e) { Log.w(LOG_TAG, "Feature could not be successfully parsed " + geoJsonFeature.toString()); return null; } return new GeoJsonFeature(geometry, id, properties, boundingBox); }
Example #8
Source File: AutoCompleteAdapter.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
private void displayPredictiveResults( String query ) { //Southwest corner to Northeast corner. LatLngBounds bounds = new LatLngBounds( new LatLng( 39.906374, -105.122337 ), new LatLng( 39.949552, -105.068779 ) ); //Filter: https://developers.google.com/places/supported_types#table3 List<Integer> filterTypes = new ArrayList<Integer>(); filterTypes.add( Place.TYPE_ESTABLISHMENT ); Places.GeoDataApi.getAutocompletePredictions( mGoogleApiClient, query, bounds, AutocompleteFilter.create( filterTypes ) ) .setResultCallback ( new ResultCallback<AutocompletePredictionBuffer>() { @Override public void onResult( AutocompletePredictionBuffer buffer ) { if( buffer == null ) return; if( buffer.getStatus().isSuccess() ) { for( AutocompletePrediction prediction : buffer ) { //Add as a new item to avoid IllegalArgumentsException when buffer is released add( new AutoCompletePlace( prediction.getPlaceId(), prediction.getDescription() ) ); } } //Prevent memory leak by releasing buffer buffer.release(); } }, 60, TimeUnit.SECONDS ); }
Example #9
Source File: CameraUpdateFactoryImpl.java From android_packages_apps_GmsCore with Apache License 2.0 | 5 votes |
@Override public IObjectWrapper newLatLngBounds(final LatLngBounds bounds, int padding) throws RemoteException { Log.d(TAG, "newLatLngBounds"); return new ObjectWrapper<CameraUpdate>(new MapPositionCameraUpdate() { @Override MapPosition getMapPosition(Map map) { MapPosition mapPosition = map.getMapPosition(); mapPosition.setByBoundingBox(GmsMapsTypeHelper.fromLatLngBounds(bounds), map.getWidth(), map.getHeight()); return mapPosition; } }); }
Example #10
Source File: EntityMapActivity.java From commcare-android with Apache License 2.0 | 5 votes |
@Override public void onMapReady(final GoogleMap map) { mMap = map; if (entityLocations.size() > 0) { LatLngBounds.Builder builder = new LatLngBounds.Builder(); // Add markers to map and find bounding region for (Pair<Entity<TreeReference>, LatLng> entityLocation : entityLocations) { Marker marker = mMap.addMarker(new MarkerOptions() .position(entityLocation.second) .title(entityLocation.first.getFieldString(0)) .snippet(entityLocation.first.getFieldString(1))); markerReferences.put(marker, entityLocation.first.getElement()); builder.include(entityLocation.second); } final LatLngBounds bounds = builder.build(); // Move camera to be include all markers mMap.setOnMapLoadedCallback(() -> mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, MAP_PADDING))); } mMap.setOnInfoWindowClickListener(this); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mMap.setMyLocationEnabled(true); } }
Example #11
Source File: KmlFeatureParser.java From android-maps-utils with Apache License 2.0 | 5 votes |
/** * Creates a new GroundOverlay object (created if a GroundOverlay tag is read by the * XmlPullParser) and assigns specific elements read from the parser to the GroundOverlay */ /* package */ static KmlGroundOverlay createGroundOverlay(XmlPullParser parser) throws IOException, XmlPullParserException { float drawOrder = 0.0f; float rotation = 0.0f; int visibility = 1; String imageUrl = null; LatLngBounds latLonBox; HashMap<String, String> properties = new HashMap<String, String>(); HashMap<String, Double> compassPoints = new HashMap<String, Double>(); int eventType = parser.getEventType(); while (!(eventType == END_TAG && parser.getName().equals("GroundOverlay"))) { if (eventType == START_TAG) { if (parser.getName().equals("Icon")) { imageUrl = getImageUrl(parser); } else if (parser.getName().equals("drawOrder")) { drawOrder = Float.parseFloat(parser.nextText()); } else if (parser.getName().equals("visibility")) { visibility = Integer.parseInt(parser.nextText()); } else if (parser.getName().equals("ExtendedData")) { properties.putAll(setExtendedDataProperties(parser)); } else if (parser.getName().equals("rotation")) { rotation = getRotation(parser); } else if (parser.getName().matches(PROPERTY_REGEX) || parser.getName().equals("color")) { properties.put(parser.getName(), parser.nextText()); } else if (parser.getName().matches(COMPASS_REGEX)) { compassPoints.put(parser.getName(), Double.parseDouble(parser.nextText())); } } eventType = parser.next(); } latLonBox = createLatLngBounds(compassPoints.get("north"), compassPoints.get("south"), compassPoints.get("east"), compassPoints.get("west")); return new KmlGroundOverlay(imageUrl, latLonBox, drawOrder, visibility, properties, rotation); }
Example #12
Source File: MarkerDemoActivity.java From android-samples with Apache License 2.0 | 5 votes |
@Override public void onMapReady(GoogleMap map) { mMap = map; // Hide the zoom controls as the button panel will cover it. mMap.getUiSettings().setZoomControlsEnabled(false); // Add lots of markers to the map. addMarkersToMap(); // Setting an info window adapter allows us to change the both the contents and look of the // info window. mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter()); // Set listeners for marker events. See the bottom of this class for their behavior. mMap.setOnMarkerClickListener(this); mMap.setOnInfoWindowClickListener(this); mMap.setOnMarkerDragListener(this); mMap.setOnInfoWindowCloseListener(this); mMap.setOnInfoWindowLongClickListener(this); // Override the default content description on the view, for accessibility mode. // Ideally this string would be localised. mMap.setContentDescription("Map with lots of markers."); LatLngBounds bounds = new LatLngBounds.Builder() .include(PERTH) .include(SYDNEY) .include(ADELAIDE) .include(BRISBANE) .include(MELBOURNE) .include(DARWIN) .build(); mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50)); }
Example #13
Source File: PlacesAutoCompleteAdapter.java From GoogleAutoCompleteWithRecyclerView with GNU General Public License v2.0 | 5 votes |
public PlacesAutoCompleteAdapter(Context context, int resource, GoogleApiClient googleApiClient, LatLngBounds bounds, AutocompleteFilter filter) { mContext = context; layout = resource; mGoogleApiClient = googleApiClient; mBounds = bounds; mPlaceFilter = filter; }
Example #14
Source File: MapPoiHandler.java From overpasser with Apache License 2.0 | 5 votes |
@Background void fetchPois(LatLngBounds bounds) { OverpassQueryResult result = overApiAdapter.search(bounds); if (result != null) { for (Element poi : result.elements) { if (!alreadyStored(poi)) { fixTitle(poi); storePoi(poi); showPoi(poi); } } } }
Example #15
Source File: ClusterPoint.java From clusterkraf with Apache License 2.0 | 5 votes |
LatLngBounds getBoundsOfInputPoints() { if (boundsOfInputPoints == null) { LatLngBounds.Builder builder = LatLngBounds.builder(); for (InputPoint inputPoint : pointsInClusterList) { builder.include(inputPoint.getMapPosition()); } boundsOfInputPoints = builder.build(); } return boundsOfInputPoints; }
Example #16
Source File: PlaceAutocompleteAdapter.java From place-search-dialog with Apache License 2.0 | 5 votes |
/** * Initializes with a resource for text rows and autocomplete query bounds. * * @see ArrayAdapter#ArrayAdapter(Context, int) */ public PlaceAutocompleteAdapter(Context context, GoogleApiClient googleApiClient, LatLngBounds bounds, AutocompleteFilter filter) { super(context, android.R.layout.simple_expandable_list_item_2, android.R.id.text1); mGoogleApiClient = googleApiClient; mBounds = bounds; mPlaceFilter = filter; }
Example #17
Source File: PlaceAutocompleteAdapter.java From ExamplesAndroid with Apache License 2.0 | 5 votes |
/** * Initializes with a resource for text rows and autocomplete query bounds. * * @see android.widget.ArrayAdapter#ArrayAdapter(android.content.Context, int) */ public PlaceAutocompleteAdapter(Context context, GoogleApiClient googleApiClient, LatLngBounds bounds, AutocompleteFilter filter) { super(context, android.R.layout.simple_expandable_list_item_2, android.R.id.text1); mGoogleApiClient = googleApiClient; mBounds = bounds; mPlaceFilter = filter; }
Example #18
Source File: PlaceAutocompleteAdapter.java From android-play-places with Apache License 2.0 | 5 votes |
/** * Initializes with a resource for text rows and autocomplete query bounds. * * @see android.widget.ArrayAdapter#ArrayAdapter(android.content.Context, int) */ public PlaceAutocompleteAdapter(Context context, GeoDataClient geoDataClient, LatLngBounds bounds, AutocompleteFilter filter) { super(context, android.R.layout.simple_expandable_list_item_2, android.R.id.text1); mGeoDataClient = geoDataClient; mBounds = bounds; mPlaceFilter = filter; }
Example #19
Source File: RichShape.java From richmaps with Apache License 2.0 | 5 votes |
public boolean boundsIntersects(final LatLngBounds test) { LatLngBounds bounds = getBounds(); if (bounds == null || test == null) { return false; } return RichUtils.intersectsRectangle(test.southwest.longitude, test.southwest.latitude, test.northeast.longitude, test.northeast.latitude, bounds.southwest.longitude, bounds.southwest.latitude, bounds.northeast.longitude, bounds.northeast.latitude); }
Example #20
Source File: GoogleMapUtis.java From Airbnb-Android-Google-Map-View with MIT License | 5 votes |
public static void fixZoomForMarkers(GoogleMap googleMap, List<Marker> markers) { if (markers!=null && markers.size() > 0) { LatLngBounds.Builder bc = new LatLngBounds.Builder(); for (Marker marker : markers) { bc.include(marker.getPosition()); } googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), 50),4000,null); } }
Example #21
Source File: GoogleMapUtis.java From Airbnb-Android-Google-Map-View with MIT License | 5 votes |
public static void fixZoomForLatLngs(GoogleMap googleMap, List<LatLng> latLngs) { if (latLngs!=null && latLngs.size() > 0) { LatLngBounds.Builder bc = new LatLngBounds.Builder(); for (LatLng latLng: latLngs) { bc.include(latLng); } googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), 50),4000,null); } }
Example #22
Source File: PlaceAutocompleteAdapter.java From Airbnb-Android-Google-Map-View with MIT License | 5 votes |
/** * Initializes with a resource for text rows and autocomplete query bounds. * * @see ArrayAdapter#ArrayAdapter(Context, int) */ public PlaceAutocompleteAdapter(Context context, int resource, GoogleApiClient googleApiClient, LatLngBounds bounds, AutocompleteFilter filter) { super(context, resource); mResultList = new ArrayList<>(); mContext = context; mGoogleApiClient = googleApiClient; mBounds = bounds; mPlaceFilter = filter; }
Example #23
Source File: EmergencyInteractorImpl.java From Saude-no-Mapa with MIT License | 5 votes |
@Override public void animateCameraToAllEstablishments(GoogleMap mMap) { if (mMap != null) { LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (Marker marker : mDeviceMarkerHash.values()) { builder.include(marker.getPosition()); } LatLngBounds bounds = builder.build(); mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100)); } }
Example #24
Source File: EstablishmentInteractorImpl.java From Saude-no-Mapa with MIT License | 5 votes |
@Override public void animateCameraToAllEstablishments(GoogleMap mMap) { if (mMap != null) { LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (Marker marker : mDeviceMarkerHash.values()) { builder.include(marker.getPosition()); } LatLngBounds bounds = builder.build(); mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100)); } }
Example #25
Source File: MapViewPager.java From MapViewPager with Apache License 2.0 | 5 votes |
private CameraUpdate getDefaultPagePosition(final MultiAdapter adapter, int page) { if (allMarkers.get(page).size() == 0) return null; if (allMarkers.get(page).size() == 1) return CameraUpdateFactory.newCameraPosition(adapter.getCameraPositions(page).get(0)); // more than 1 marker on this page LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (Marker marker : allMarkers.get(page)) if (marker != null) builder.include(marker.getPosition()); LatLngBounds bounds = builder.build(); return CameraUpdateFactory.newLatLngBounds(bounds, mapOffset); }
Example #26
Source File: MapViewPager.java From MapViewPager with Apache License 2.0 | 5 votes |
private void initDefaultPositions(final MultiAdapter adapter) { // each page defaultPositions = new LinkedList<>(); for (int i = 0; i < adapter.getCount() ; i++) { defaultPositions.add(getDefaultPagePosition(adapter, i)); } // global LinkedList<Marker> all = new LinkedList<>(); for (List<Marker> list : allMarkers) if (list != null) all.addAll(list); LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (Marker marker : all) if (marker != null) builder.include(marker.getPosition()); LatLngBounds bounds = builder.build(); defaultPosition = CameraUpdateFactory.newLatLngBounds(bounds, mapOffset); }
Example #27
Source File: Gallery.java From animation-samples with Apache License 2.0 | 5 votes |
@NonNull public LatLngBounds getBounds() { if (null == mLatLngBounds) { mLatLngBounds = calculateBounds(); } return mLatLngBounds; }
Example #28
Source File: AtlasFragment.java From memoir with Apache License 2.0 | 5 votes |
public void refreshMarkers() { mMap.clear(); // Find notes with location noteList = new ArrayList<>(); List<Note> notes = NotesDatabase.getInstance(getContext()).getNotes(); for (int i = 0; i < notes.size(); i++) { if (notes.get(i).location.placeName.length() != 0) { noteList.add(notes.get(i)); LatLng latLng = new LatLng(notes.get(i).location.latitude, notes.get(i).location.longitude); mMap.addMarker(new MarkerOptions().position(latLng).title(notes.get(i).title)); } } if (!noteList.isEmpty()) { // Zoom to markers mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition cameraPosition) { mMap.setOnCameraChangeListener(null); LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (int i = 0; i < noteList.size(); i++) { builder.include(new LatLng(noteList.get(i).location.latitude, noteList.get(i).location.longitude)); } LatLngBounds bounds = builder.build(); int padding = 200; // offset from edges of the map in pixels CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding); mMap.moveCamera(cu); } }); } }
Example #29
Source File: AutoCompleteAdapter.java From AutocompleteLocation with Apache License 2.0 | 5 votes |
public AutoCompleteAdapter(Context context, GoogleApiClient googleApiClient, LatLngBounds bounds, AutocompleteFilter filter) { super(context, android.R.layout.simple_expandable_list_item_2, android.R.id.text1); mGoogleApiClient = googleApiClient; mBounds = bounds; mPlaceFilter = filter; }
Example #30
Source File: MapFragment.java From mirror with Apache License 2.0 | 5 votes |
@SuppressWarnings("ResourceType") @Override public void onMapReady(GoogleMap map) { // set the map mMap = map; // now display the map mMap.setMyLocationEnabled(true); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mFromMarkerOptions.getPosition(), 14)); mMap.addMarker(mFromMarkerOptions); if (mToMarkerOptions != null) { mMap.addMarker(mToMarkerOptions); LatLngBounds bounds = LatLngBounds.builder() .include(mFromMarkerOptions.getPosition()) .include(mToMarkerOptions.getPosition()) .build(); mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50)); new Routing.Builder() .travelMode(AbstractRouting.TravelMode.DRIVING) .withListener(this) .alternativeRoutes(true) .waypoints(mFromMarkerOptions.getPosition(), mToMarkerOptions.getPosition()) .build() .execute(); } }