Java Code Examples for com.google.android.gms.maps.CameraUpdateFactory#newLatLngBounds()
The following examples show how to use
com.google.android.gms.maps.CameraUpdateFactory#newLatLngBounds() .
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: LocatrFragment.java From AndroidProgramming3e with Apache License 2.0 | 5 votes |
private void updateUI() { if (mMap == null || mMapImage == null) { return; } LatLng itemPoint = new LatLng(mMapItem.getLat(), mMapItem.getLon()); LatLng myPoint = new LatLng( mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()); BitmapDescriptor itemBitmap = BitmapDescriptorFactory.fromBitmap(mMapImage); MarkerOptions itemMarker = new MarkerOptions() .position(itemPoint) .icon(itemBitmap); MarkerOptions myMarker = new MarkerOptions() .position(myPoint); mMap.clear(); mMap.addMarker(itemMarker); mMap.addMarker(myMarker); LatLngBounds bounds = new LatLngBounds.Builder() .include(itemPoint) .include(myPoint) .build(); int margin = getResources().getDimensionPixelSize(R.dimen.map_inset_margin); CameraUpdate update = CameraUpdateFactory.newLatLngBounds(bounds, margin); mMap.animateCamera(update); }
Example 2
Source File: NiboOriginDestinationPickerFragment.java From Nibo with MIT License | 5 votes |
private void showBothMarkersAndGetDirections() { if (mOriginMapMarker != null && mDestinationMarker != null) { int width = getResources().getDisplayMetrics().widthPixels; int padding = (int) (width * 0.10); // CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(getLatLngBoundsForMarkers(), padding); mMap.moveCamera(cu); mMap.animateCamera(cu); sendRequest(mOriginMapMarker.getPosition(), mDestinationMarker.getPosition()); } else { } }
Example 3
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 4
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 5
Source File: MyTracksMapFragment.java From mytracks with Apache License 2.0 | 5 votes |
/** * Moves the camera over the current track. */ private void moveCameraOverTrack() { /** * Check all the required variables. */ if (googleMap == null || currentTrack == null || currentTrack.getNumberOfPoints() < 2 || mapView == null || mapView.getWidth() == 0 || mapView.getHeight() == 0) { return; } TripStatistics tripStatistics = currentTrack.getTripStatistics(); int latitudeSpanE6 = tripStatistics.getTop() - tripStatistics.getBottom(); int longitudeSpanE6 = tripStatistics.getRight() - tripStatistics.getLeft(); if (latitudeSpanE6 > 0 && latitudeSpanE6 < 180E6 && longitudeSpanE6 > 0 && longitudeSpanE6 < 360E6) { LatLng southWest = new LatLng( tripStatistics.getBottomDegrees(), tripStatistics.getLeftDegrees()); LatLng northEast = new LatLng( tripStatistics.getTopDegrees(), tripStatistics.getRightDegrees()); LatLngBounds bounds = LatLngBounds.builder().include(southWest).include(northEast).build(); /** * Note cannot call CameraUpdateFactory.newLatLngBounds(LatLngBounds * bounds, int padding) if the map view has not undergone layout. Thus * calling CameraUpdateFactory.newLatLngBounds(LatLngBounds bounds, int * width, int height, int padding) after making sure that mapView is valid * in the above code. */ CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds( bounds, mapView.getWidth(), mapView.getHeight(), MAP_VIEW_PADDING); googleMap.moveCamera(cameraUpdate); } }
Example 6
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 7
Source File: Clusterkraf.java From clusterkraf with Apache License 2.0 | 5 votes |
/** * Animate the camera so all of the InputPoint objects represented by the * passed ClusterPoint are in view * * @param clusterPoint */ public void zoomToBounds(ClusterPoint clusterPoint) { GoogleMap map = mapRef.get(); if (map != null && clusterPoint != null) { innerCallbackListener.clusteringOnCameraChangeListener.setDirty(System.currentTimeMillis()); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(clusterPoint.getBoundsOfInputPoints(), options.getZoomToBoundsPadding()); map.animateCamera(cameraUpdate, options.getZoomToBoundsAnimationDuration(), null); } }
Example 8
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 9
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 10
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); }