Java Code Examples for com.google.android.gms.maps.model.LatLngBounds#Builder
The following examples show how to use
com.google.android.gms.maps.model.LatLngBounds#Builder .
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 |
/** * Handles the GPX button-click event, running the demo snippet {@link #loadGpxData}. */ public void onGpxButtonClick(View view) { try { mCapturedLocations = loadGpxData(Xml.newPullParser(), getResources().openRawResource(R.raw.gpx_data)); findViewById(R.id.snap_to_roads).setEnabled(true); LatLngBounds.Builder builder = new LatLngBounds.Builder(); PolylineOptions polyline = new PolylineOptions(); for (LatLng ll : mCapturedLocations) { com.google.android.gms.maps.model.LatLng mapPoint = new com.google.android.gms.maps.model.LatLng(ll.lat, ll.lng); builder.include(mapPoint); polyline.add(mapPoint); } mMap.addPolyline(polyline.color(Color.RED)); mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0)); } catch (XmlPullParserException | IOException e) { e.printStackTrace(); toastException(e); } }
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: NativeGoogleMapFragment.java From AirMapView with Apache License 2.0 | 6 votes |
@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()); }
Example 4
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 5
Source File: CustomMarkerClusteringDemoActivity.java From android-maps-utils with Apache License 2.0 | 6 votes |
@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; }
Example 6
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 7
Source File: DriverMapPresenter.java From ridesharing-android with MIT License | 5 votes |
private void updateMapCamera() { if (!mState.newOrders.isEmpty()) { LatLngBounds.Builder builder = new LatLngBounds.Builder(); if (mState.currentLocation != null) { builder.include( new LatLng(mState.currentLocation.getLatitude(), mState.currentLocation.getLongitude()) ); } for (Order order : mState.newOrders.values()) { builder.include(order.pickup.getLatLng()); } animateCamera(builder.build()); } }
Example 8
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 9
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 10
Source File: LocationActivity.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void fetchRecentLocations(ArrayList<TLRPC.Message> messages) { LatLngBounds.Builder builder = null; if (firstFocus) { builder = new LatLngBounds.Builder(); } int date = ConnectionsManager.getInstance(currentAccount).getCurrentTime(); for (int a = 0; a < messages.size(); a++) { TLRPC.Message message = messages.get(a); if (message.date + message.media.period > date) { if (builder != null) { LatLng latLng = new LatLng(message.media.geo.lat, message.media.geo._long); builder.include(latLng); } addUserMarker(message); } } if (builder != null) { firstFocus = false; adapter.setLiveLocations(markers); if (messageObject.isLiveLocation()) { try { final LatLngBounds bounds = builder.build(); if (messages.size() > 1) { try { googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, AndroidUtilities.dp(60))); } catch (Exception e) { FileLog.e(e); } } } catch (Exception ignore) { } } } }
Example 11
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 12
Source File: MainActivity.java From android-app with GNU General Public License v2.0 | 5 votes |
@Override public void retrieveBusData(BusData busData) { List<Bus> buses = busData.getBuses(); if (buses == null) { Toast.makeText(this, getString(R.string.error_connection_server), Toast.LENGTH_SHORT).show(); return; } if (buses.isEmpty()) { Toast.makeText(this, getString(R.string.error_bus_404), Toast.LENGTH_SHORT).show(); return; } map.clear(); List<Itinerary> itineraries = busData.getItineraries(); if(itineraries != null && !itineraries.isEmpty()) { for(Itinerary itinerary: itineraries) drawItineraryPolyline(itinerary); } map.setInfoWindowAdapter(new BusInfoWindowAdapter(this)); MapMarker marker = new MapMarker(map); marker.addMarkers(buses); LatLngBounds.Builder builder = marker.getBoundsBuilder(); if (currentLocation != null) { LatLng userPosition = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()); mapMarker.markUserPosition(this, userPosition); builder.include(userPosition); } LatLngBounds bounds = builder.build(); int padding = 100; // offset from edges of the map in pixels CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding); map.moveCamera(cu); map.animateCamera(cu); }
Example 13
Source File: RichShape.java From richmaps with Apache License 2.0 | 5 votes |
public LatLngBounds getBounds() { if (points.isEmpty()) { return null; } LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (RichPoint point : points) { if (point.getPosition() != null) { builder.include(point.getPosition()); } } return builder.build(); }
Example 14
Source File: LocationActivity.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void fetchRecentLocations(ArrayList<TLRPC.Message> messages) { LatLngBounds.Builder builder = null; if (firstFocus) { builder = new LatLngBounds.Builder(); } int date = ConnectionsManager.getInstance(currentAccount).getCurrentTime(); for (int a = 0; a < messages.size(); a++) { TLRPC.Message message = messages.get(a); if (message.date + message.media.period > date) { if (builder != null) { LatLng latLng = new LatLng(message.media.geo.lat, message.media.geo._long); builder.include(latLng); } addUserMarker(message); } } if (builder != null) { firstFocus = false; adapter.setLiveLocations(markers); if (messageObject.isLiveLocation()) { try { final LatLngBounds bounds = builder.build(); if (messages.size() > 1) { try { googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, AndroidUtilities.dp(60))); } catch (Exception e) { FileLog.e(e); } } } catch (Exception ignore) { } } } }
Example 15
Source File: MapActivity.java From homeassist with Apache License 2.0 | 4 votes |
@Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; mMap.setOnMarkerClickListener(this); UiSettings uiSettings = mMap.getUiSettings(); uiSettings.setCompassEnabled(true); uiSettings.setZoomControlsEnabled(true); uiSettings.setMyLocationButtonEnabled(true); uiSettings.setAllGesturesEnabled(true); uiSettings.setMyLocationButtonEnabled(true); DatabaseManager databaseManager = DatabaseManager.getInstance(this); ArrayList<Entity> devices = databaseManager.getDeviceLocations(); LatLngBounds.Builder builder = new LatLngBounds.Builder(); int zoneCount = 0; int deviceCount = 0; for (Entity device : devices) { Log.d("YouQi", "Device: " + CommonUtil.deflate(device)); LatLng latLng = device.getLocation(); if (latLng == null) continue; builder.include(latLng); if (device.isZone()) { zoneCount += 1; Log.d("YouQi", "Zone!!"); Circle circle = mMap.addCircle(new CircleOptions() .center(latLng) // .strokeColor(Color.RED) .strokeColor(Color.parseColor("#FF5722")) .fillColor(Color.parseColor("#33FFAB91"))); if (device.attributes.radius != null) { circle.setRadius(device.attributes.radius.floatValue()); } if (device.hasMdiIcon()) { Log.d("YouQi", "hasMdiIcon"); mMap.addMarker(new MarkerOptions() .icon(BitmapDescriptorFactory.fromBitmap(mifZoneIcon.makeMaterialIcon(device.getMdiIcon()))) .position(latLng) .zIndex(1.0f) .anchor(mifZoneIcon.getAnchorU(), mifZoneIcon.getAnchorV())); } else { Log.d("YouQi", "nope"); mMap.addMarker(new MarkerOptions() .icon(BitmapDescriptorFactory.fromBitmap(mifZoneText.makeIcon(device.getFriendlyName()))) .position(latLng) .zIndex(1.0f) .anchor(mifZoneText.getAnchorU(), mifZoneText.getAnchorV())); } } else if (device.isDeviceTracker()) { deviceCount += 1; Marker marker = createMarker(device); markers.put(device.entityId, marker); } } if (deviceCount == 0 && zoneCount == 0) { mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.3333395, -30.3274332), 2)); new MaterialDialog.Builder(this) .cancelable(false) .title(R.string.title_nozone) .content(R.string.content_nozone) .positiveText(R.string.button_continue) .positiveColorRes(R.color.md_red_500) .buttonRippleColorRes(R.color.md_grey_200) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { dialog.dismiss(); } }) .show(); } else { LatLngBounds bounds = builder.build(); int width = getResources().getDisplayMetrics().widthPixels; int height = getResources().getDisplayMetrics().heightPixels; int padding = (int) (width * 0.20); // offset from edges of the map 10% of screen CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(bounds.getCenter(), 10)); mMap.animateCamera(cu); } //mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); }
Example 16
Source File: NiboOriginDestinationPickerFragment.java From Nibo with MIT License | 4 votes |
LatLngBounds getLatLngBoundsForMarkers() { LatLngBounds.Builder builder = new LatLngBounds.Builder(); builder.include(mOriginMapMarker.getPosition()); builder.include(mDestinationMarker.getPosition()); return builder.build(); }
Example 17
Source File: HistorySingleActivity.java From UberClone with MIT License | 4 votes |
@Override public void onRoutingSuccess(ArrayList<Route> route, int shortestRouteIndex) { LatLngBounds.Builder builder = new LatLngBounds.Builder(); builder.include(pickupLatLng); builder.include(destinationLatLng); LatLngBounds bounds = builder.build(); int width = getResources().getDisplayMetrics().widthPixels; int padding = (int) (width*0.2); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding); mMap.animateCamera(cameraUpdate); mMap.addMarker(new MarkerOptions().position(pickupLatLng).title("pickup location").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_pickup))); mMap.addMarker(new MarkerOptions().position(destinationLatLng).title("destination")); if(polylines.size()>0) { for (Polyline poly : polylines) { poly.remove(); } } polylines = new ArrayList<>(); //add route(s) to the map. for (int i = 0; i <route.size(); i++) { //In case of more than 5 alternative routes int colorIndex = i % COLORS.length; PolylineOptions polyOptions = new PolylineOptions(); polyOptions.color(getResources().getColor(COLORS[colorIndex])); polyOptions.width(10 + i * 3); polyOptions.addAll(route.get(i).getPoints()); Polyline polyline = mMap.addPolyline(polyOptions); polylines.add(polyline); Toast.makeText(getApplicationContext(),"Route "+ (i+1) +": distance - "+ route.get(i).getDistanceValue()+": duration - "+ route.get(i).getDurationValue(),Toast.LENGTH_SHORT).show(); } }
Example 18
Source File: MapViewPager.java From MapViewPager with Apache License 2.0 | 4 votes |
private void initDefaultPosition() { LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (Marker marker : markers) if (marker != null) builder.include(marker.getPosition()); LatLngBounds bounds = builder.build(); defaultPosition = CameraUpdateFactory.newLatLngBounds(bounds, mapOffset); }
Example 19
Source File: LocationActivity.java From Telegram with GNU General Public License v2.0 | 4 votes |
private void fetchRecentLocations(ArrayList<TLRPC.Message> messages) { LatLngBounds.Builder builder = null; if (firstFocus) { builder = new LatLngBounds.Builder(); } int date = getConnectionsManager().getCurrentTime(); for (int a = 0; a < messages.size(); a++) { TLRPC.Message message = messages.get(a); if (message.date + message.media.period > date) { if (builder != null) { LatLng latLng = new LatLng(message.media.geo.lat, message.media.geo._long); builder.include(latLng); } addUserMarker(message); } } if (builder != null) { firstFocus = false; adapter.setLiveLocations(markers); if (messageObject.isLiveLocation()) { try { LatLngBounds bounds = builder.build(); LatLng center = bounds.getCenter(); LatLng northEast = move(center, 100, 100); LatLng southWest = move(center, -100, -100); builder.include(southWest); builder.include(northEast); bounds = builder.build(); if (messages.size() > 1) { try { googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, AndroidUtilities.dp(60))); } catch (Exception e) { FileLog.e(e); } } } catch (Exception ignore) { } } } }
Example 20
Source File: MapMarker.java From android-app with GNU General Public License v2.0 | 4 votes |
public LatLngBounds.Builder getBoundsBuilder(){ return builder; }