Java 类com.google.android.gms.maps.model.LatLngBounds 实例源码

项目:FiveMinsMore    文件:MapUtils.java   
public static void zoomToPolyline(GoogleMap map, Polyline p) {
    if (p == null || p.getPoints().isEmpty())
        return;

    LatLngBounds.Builder builder = LatLngBounds.builder();

    for (LatLng latLng : p.getPoints()) {
        builder.include(latLng);
    }
    final LatLngBounds bounds = builder.build();

    try{
    map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 150));
    } catch (Exception e){
        e.printStackTrace();
    }
}
项目:Pickr    文件:DataManager.java   
public Observable<PlacePrediction> getAutocompleteResults(final GoogleApiClient mGoogleApiClient, final String query, final LatLngBounds bounds) {
    return Observable.create(new Observable.OnSubscribe<PlacePrediction>() {
        @Override
        public void call(Subscriber<? super PlacePrediction> subscriber) {

            PendingResult<AutocompletePredictionBuffer> results =
                    Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, query,
                            bounds, null);

            AutocompletePredictionBuffer autocompletePredictions = results
                    .await(60, TimeUnit.SECONDS);

            final Status status = autocompletePredictions.getStatus();
            if (!status.isSuccess()) {
                autocompletePredictions.release();
                subscriber.onError(null);
            } else {
                for (AutocompletePrediction autocompletePrediction : autocompletePredictions) {
                    subscriber.onNext(
                            new PlacePrediction(
                                    autocompletePrediction.getPlaceId(),
                                    autocompletePrediction.getDescription()
                            ));
                }
                autocompletePredictions.release();
                subscriber.onCompleted();
            }
        }
    });
}
项目:event-me    文件:LiveShare.java   
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_liveshare);
        builder = new LatLngBounds.Builder();
        userdata = FirebaseDatabase.getInstance().getReference().child(Constants.users);

        user = FirebaseAuth.getInstance().getCurrentUser();
        key = (String) getIntent().getExtras().get("uid");
        livedata = FirebaseDatabase.getInstance().getReference(Constants.events).child(key).child(Constants.livepart);
        lat = (Double) getIntent().getExtras().get("lat");
        lon = (Double) getIntent().getExtras().get("lon");
        builder.include(new LatLng(lat,lon));

        SupportMapFragment mapFragment =
                (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
//            Intent  i = new Intent(getApplicationContext(), LocationData.class);
//            startService(i);


    }
项目:FiveMinsMore    文件:CustomRenderer.java   
@Override
public boolean onClusterClick(Cluster<CustomMarker> cluster) {
    // 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 (CustomMarker item : cluster.getItems()) {
        builder.include(item.getPosition());
    }
    // Get the LatLngBounds
    final LatLngBounds bounds = builder.build();

    // Animate camera to the bounds
    try {
        mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 150));
    } catch (Exception e) {
        e.printStackTrace();
    }

    return true;
}
项目:Dispatch    文件:MainActivity.java   
public void PlacePinAndPositionCamera(LatLng addressPosition) {

        MarkerOptions markerOptions = new MarkerOptions();
        markerOptions.position(addressPosition);
        mMap.addMarker(markerOptions
                .title("Crisis Location").icon(BitmapDescriptorFactory
                        .defaultMarker(BitmapDescriptorFactory.HUE_RED)));
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(addressPosition, 12));
        LatLngBounds.Builder builder = new LatLngBounds.Builder();

        builder.include(addressPosition);

        LatLngBounds bounds = builder.build();

        int padding = 150; // offset from edges of the map in pixels
        CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);

        mMap.animateCamera(cu);
    }
项目:hyperrail-for-android    文件:StationActivity.java   
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney, Australia, and move the camera.
    LatLng stationLocation = new LatLng(mStation.getLatitude(), mStation.getLongitude());
    mMap.addMarker(new MarkerOptions().position(stationLocation).title(mStation.getLocalizedName()));
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(stationLocation, 15));
    mMap.setBuildingsEnabled(true);
    mMap.setTrafficEnabled(false);
    mMap.setMinZoomPreference(10);
    mMap.setMaxZoomPreference(18);
    mMap.setLatLngBoundsForCameraTarget(new LatLngBounds(stationLocation,stationLocation));
    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        mMap.setMyLocationEnabled(true);
    }
}
项目:Android-Programming-BigNerd    文件:LocatrFragment.java   
private void updateUI() {
    if (mMap == null || mMapImage == null) {
        return;
    }
    Log.d(TAG, "updateUI: ");
    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);
}
项目:mobile-app-dev-book    文件:TripMapFragment.java   
private void refreshMarkers() {
//        if (allMarkers.size() == allTrips.size()) return;
        LatLngBounds.Builder boundBuilder = new LatLngBounds.Builder();
        allMarkers.clear();
        gMap.clear();
        for (Trip t : allTrips) {
            DateTime begDate = DateTime.parse(t.getStartDate());
            DateTime endDate = DateTime.parse(t.getEndDate());
            LatLng thisLoc = new LatLng(t.getLat(), t.getLng());
            Marker m = gMap.addMarker(
                    new MarkerOptions().position(thisLoc).title(t.getName())
                            .snippet(formatDate(begDate, endDate)));
            m.setTag(t);
            allMarkers.add(m);
            boundBuilder.include(thisLoc);
        }
        if (allMarkers.size() > 0) {
            int screenWidth = getResources().getDisplayMetrics().widthPixels;
            int screenHeight = getResources().getDisplayMetrics().heightPixels;
            LatLngBounds bound = boundBuilder.build();
            CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bound,
                    screenWidth, screenHeight, 56);
            gMap.animateCamera(cameraUpdate);
        }
    }
项目:geopackage-android-map    文件:MapUtils.java   
/**
 * 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;
}
项目:RoadLab-Pro    文件:MeasurementsGoogleMapHelper.java   
public void fitMap(GoogleMap map, List<LatLng> locations, boolean animate, int padding) {
    if (map == null) {
        return;
    }
    LatLngBounds bounds = getLatLngBounds(locations);
    if (bounds == null ) {
        return;
    }
    CameraUpdate cUpdate = null;
    try {
        cUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);
        if (animate) {
            map.animateCamera(cUpdate);
        } else {
            map.moveCamera(cUpdate);
        }
    } catch (Exception e) {
        Log.e(TAG, e != null && e.getMessage() != null ? e.getMessage() : "");
    }
}
项目:WalkGraph    文件:MapFragmentImpl.java   
/**
 * Zooms in on map based most recent or previous day's graph.
 *
 * Uses the first day's location as the first point and
 * the last location of graph as the last point for area to zoom
 * in on around the map.
 *
 * Calls drawGraph(graph) to show graph points.
 */
@Override
public void updateMapArea() {
    Graph graph = mapPresenter.getRecentGraph();
    if (googleMap == null){
        Log.d(TAG, "Google map is null");
        return;
    }

    Location first = graph.getLocations().get(0);
    Location last = graph.getLocations().get(graph.getLocations().size() - 1);
    LatLng firstPoint = new LatLng(first.getLatitude(), first.getLongitude());
    LatLng lastPoint = new LatLng(last.getLatitude(), last.getLongitude());


    LatLngBounds bounds = new LatLngBounds.Builder()
            .include(firstPoint)
            .include(lastPoint)
            .build();
    int margin = getResources().getDimensionPixelSize(R.dimen.map_inset);
    CameraUpdate update = CameraUpdateFactory.newLatLngBounds(bounds, margin);
    googleMap.animateCamera(update);
    drawGraph(graph);
}
项目:instantsearch-android-examples    文件:MapWidget.java   
private void updateMapPOIs() {
    googleMap.clear();
    if (hits.isEmpty()) {
        return;
    }
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (final JSONObject hit: hits) {
        final MarkerOptions marker = HitMarker.marker(hit);
        builder.include(marker.getPosition());
        googleMap.addMarker(marker);
    }
    LatLngBounds bounds = builder.build();
    // update the camera
    int padding = 10;
    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
    googleMap.animateCamera(cu);
}
项目:appez-android    文件:SmartMapHandlerActivity.java   
private void addPanPropertiesToMap() {
    LatLngBounds bounds = null;
    Builder latLngBoundBuilder = new LatLngBounds.Builder();
    if (punchLocationCollection != null && punchLocationCollection.size() > 0) {
        int totalLocations = punchLocationCollection.size();
        for (int currentLocation = 0; currentLocation < totalLocations; currentLocation++) {
            LatLng latLng = new LatLng(Double.parseDouble(punchLocationCollection.get(currentLocation).getLatitude()), Double.parseDouble(punchLocationCollection.get(currentLocation)
                    .getLongitude()));
            latLngBoundBuilder = latLngBoundBuilder.include(latLng);
        }
    }

    if (deviceCurrentLocation != null) {
        latLngBoundBuilder.include(new LatLng(deviceCurrentLocation.getLatitude(), deviceCurrentLocation.getLongitude()));
    }

    // Build the map with the bounds that encompass all the
    // specified location as well the current location
    bounds = latLngBoundBuilder.build();

    mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
    // Zoom in, animating the camera.
    // mMap.animateCamera(CameraUpdateFactory.zoomTo(50), 2000, null);
}
项目:MikuyConcept    文件:ExploreFragment.java   
@Override
public void showAvailableRestaurants(List<Restaurant> items) {
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (Restaurant restaurant : items) {
        Marker marker = this.googleMap.addMarker(
                new MarkerOptions()
                        .position(new LatLng(restaurant.latitude, restaurant.longitude))
                        .title(restaurant.name)
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.mikuy_marker))
                        .snippet(restaurant.category));
        marker.setTag(restaurant);
        builder.include(marker.getPosition());
    }
    LatLngBounds bounds = builder.build();
    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 100);
    this.googleMap.moveCamera(cu);
}
项目:travelers-diary    文件:ReminderItemFragment.java   
@OnClick(R.id.reminder_item_waypoint_title_text_view)
public void onWaypointTitleClick() {
    PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
    if (mRemindItem.getWaypoint() != null) {
        LocationPoint locationPoint = mRemindItem.getWaypoint().getLocation();
        LatLng latLng = new LatLng(locationPoint.getLatitude(), locationPoint.getLongitude());
        LatLngBounds latLngBounds = new LatLngBounds(latLng, latLng);
        builder.setLatLngBounds(latLngBounds);
    }

    Intent intent = null;
    try {
        intent = builder.build(getActivity());
    } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }
    mProgressDialog = ProgressDialog.show(mContext,
            getString(R.string.reminder_place_picker_progress_dialog_title),
            getString(R.string.reminder_place_picker_progress_dialog_message), true, false);
    startActivityForResult(intent, PLACE_PICKER_REQUEST);
}
项目:aken-ajalukku    文件:AbstractMapActivity.java   
@Override
public void onDirectionsTaskResponse(DirectionsTaskResponse response) {
    if (currentPolyline != null) {
        currentPolyline.remove();
    }
    Log.v(TAG, "Got directions");
    if (response != null) {
        List<LatLng> points = response.getPolylineOptions().getPoints();
        LatLngBounds.Builder bnds = LatLngBounds.builder().include(new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude()));
        for (LatLng point : points) {
            bnds.include(point);
        }
        map.animateCamera(CameraUpdateFactory.newLatLngBounds(bnds.build(), 250));
        currentPolyline = map.addPolyline(response.getPolylineOptions());
    }
}
项目:google-maps-3D-pie-chart-marker-clustering-java    文件:DemoActivity.java   
@Override
public boolean onClusterClick(Cluster<Asset> 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;
}
项目:Ridr    文件:RideView.java   
/**
 * A function to show two points of a ride on the map
 *
 * @param ride the ride
 */
public void showRide(Ride ride){
    markers.clear();
    map.clear();
    Marker pickup = map.addMarker(new MarkerOptions().position(ride.getPickupCoords()).title("Pickup: " + ride.getPickupAddress()));
    //pickup.setTitle(ride.getPickupAddress());
    markers.add(pickup);

    Marker dropoff = map.addMarker(new MarkerOptions().position(ride.getDropOffCoords()).title("Drop off: " + ride.getDropOffAddress()));
    //dropoff.setTitle(ride.getDropOffAddress());
    markers.add(dropoff);

    // Constrain map
    LatLngBounds.Builder boundedMap = new LatLngBounds.Builder();
    boundedMap.include(ride.getPickupCoords());
    boundedMap.include(ride.getDropOffCoords());

    map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundedMap.build(), 500));

    updateRideInfo(ride);
}
项目:PhoneChat    文件:PluginMap.java   
/**
 * Return the visible region of the map
 * Thanks @fschmidt
 */
@SuppressWarnings("unused")
private void getVisibleRegion(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
  VisibleRegion visibleRegion = map.getProjection().getVisibleRegion();
  LatLngBounds latLngBounds = visibleRegion.latLngBounds;
  JSONObject result = new JSONObject();
  JSONObject northeast = new JSONObject();
  JSONObject southwest = new JSONObject();
  northeast.put("lat", latLngBounds.northeast.latitude);
  northeast.put("lng", latLngBounds.northeast.longitude);
  southwest.put("lat", latLngBounds.southwest.latitude);
  southwest.put("lng", latLngBounds.southwest.longitude);
  result.put("northeast", northeast);
  result.put("southwest", southwest);

  JSONArray latLngArray = new JSONArray();
  latLngArray.put(northeast);
  latLngArray.put(southwest);
  result.put("latLngArray", latLngArray);

  callbackContext.success(result);
}
项目:PhoneChat    文件:PluginPolyline.java   
/**
 * Set points
 * @param args
 * @param callbackContext
 * @throws JSONException
 */
@SuppressWarnings("unused")
private void setPoints(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
  String id = args.getString(1);
  Polyline polyline = this.getPolyline(id);

  JSONArray points = args.getJSONArray(2);
  List<LatLng> path = PluginUtil.JSONArray2LatLngList(points);
  polyline.setPoints(path);

  LatLngBounds.Builder builder = new LatLngBounds.Builder();
  for (int i = 0; i < path.size(); i++) {
    builder.include(path.get(i));
  }
  this.objects.put("polyline_bounds_" + polyline.getId(), builder.build());

  this.sendNoResult(callbackContext);
}
项目:PhoneChat    文件:PluginPolygon.java   
/**
 * Set points
 * @param args
 * @param callbackContext
 * @throws JSONException
 */
@SuppressWarnings("unused")
private void setPoints(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
    String id = args.getString(1);
    Polygon polygon = this.getPolygon(id);

    JSONArray points = args.getJSONArray(2);
    List<LatLng> path = PluginUtil.JSONArray2LatLngList(points);
    polygon.setPoints(path);

    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (int i = 0; i < path.size(); i++) {
        builder.include(path.get(i));
    }
    this.objects.put("polygon_bounds_" + polygon.getId(), builder.build());
    this.sendNoResult(callbackContext);
}
项目:simple-map-android    文件:ActivityMap.java   
private void loadMapPins(List<Unit> units) {
    mMap.clear();
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (Unit u : units) {
        mMap.addMarker(new MarkerOptions()
                .title(u.getNome())
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_action_pin))
                .snippet(u.buildSnippet())
                .position(new LatLng(u.getGeo().getLatitude(), u.getGeo().getLongitude())));
        builder.include(new LatLng(u.getGeo().getLatitude(), u.getGeo().getLongitude()));
    }

    LatLngBounds bounds = builder.build();
    int padding = (int) (16 * getResources().getDisplayMetrics().density);
    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
    mMap.animateCamera(cu);
}
项目:Airbnb-Android-Google-Map-View    文件:MovingMarkerActivity.java   
@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);
        }
    });

}
项目:SpatiAtlas    文件:MapFragment.java   
public GeomLoader onCreateLoader(Bundle args) {
    final LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;

    final Bundle params = new Bundle();
    if (mSimplificationTolerance != -1)
        params.putDouble(GeomLoader.PARAM_SIMPLIFICATION_TOLERANCE, mSimplificationTolerance);
    if (mLimit != -1)
        params.putInt(GeomLoader.PARAM_LIMIT, mLimit);

    final GeomLoader loader = new GeomLoader(
            getActivity().getApplicationContext(),
            mTable,
            bounds,
            mProjection,
            mSelection,
            mSelectionArgs,
            mSortOrder,
            params);

    return loader;
}
项目:trail-android    文件:MapsActivity.java   
/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap map) {
    mMap = map;

    mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            builder.include(POINT_A);
            builder.include(POINT_B);
            LatLngBounds bounds = builder.build();
            CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 200);

            mMap.moveCamera(cu);
            mMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);

            startAnim();
        }
    });
}
项目:PGMacTips    文件:MapUtilities.java   
public static CameraUpdate calculateZoomLevel(@NonNull LatLng latLng, float radiusInMeters,
                                               @NonNull DisplayManagerUtilities dmu){
    if(radiusInMeters < 0){
        radiusInMeters = 10;
    }
    int width, height;
    Point point = dmu.getAppUsableScreenSize();
    if(point != null) {
        width = point.x;
        height = point.y;
    } else {
        width = dmu.getPixelsWidth();
        height = dmu.getPixelsHeight();
    }

    LatLngBounds latLngBounds = calculateBounds(latLng, radiusInMeters);
    return CameraUpdateFactory.newLatLngBounds(latLngBounds, width, height, 0);
}
项目:sample-transport-app    文件:RouteMapService.java   
/**
 * Adds the route to the map.
 *
 * @param googleMap    the map
 * @param routeMapInfo the view model containing the information for the route
 */
public void addRouteToMap(final GoogleMap googleMap, final RouteMapData routeMapInfo) {
    final LatLngBounds.Builder latLngBounds = new LatLngBounds.Builder();
    for (PolylineData polylineData : routeMapInfo.getPolylineDataList()) {
        PolylineOptions polyline = getPolylineOptions(latLngBounds, polylineData);
        if (polyline != null) {
            googleMap.addPolyline(polyline);
        }
    }
    googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            addMarker(routeMapInfo.getStartPoint(), googleMap);
            addMarker(routeMapInfo.getEndPoint(), googleMap);
            googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds.build(), 200));
        }
    });
}
项目:sample-transport-app    文件:RouteMapServiceTest.java   
@Test
public void shouldAddRouteToMap() {
    // given
    RouteMapData routeMapData = prepareRouteMapData();
    doAnswer(mapLoadedCallbackAnswer).when(googleMap).setOnMapLoadedCallback(any(GoogleMap.OnMapLoadedCallback.class));
    doAnswer(newLatLngBoundsAnswer).when(googleMap).addPolyline(any(PolylineOptions.class));
    when(CameraUpdateFactory.newLatLngBounds(any(LatLngBounds.class), anyInt())).thenReturn(cameraUpdate);

    // when
    routeMapService.addRouteToMap(googleMap, routeMapData);

    // then
    verify(googleMap, times(1)).addPolyline(any(PolylineOptions.class));
    verify(googleMap, times(2)).addMarker(any(MarkerOptions.class));
    verify(googleMap, times(1)).animateCamera(any(CameraUpdate.class));
}
项目:smartpublictransport-as    文件:LocationUtilities.java   
public static LatLngBounds detectBounds(List<LatLng> points) {
    LatLng minLatLng, maxLatLng;
    double minLat = 90, minLng = 180, maxLat = -90, maxLng = -180;

    for (LatLng latlng : points) {
        minLat = Math.min(latlng.latitude, minLat);
        maxLat = Math.max(latlng.latitude, maxLat);
        minLng = Math.min(latlng.longitude, minLng);
        maxLng = Math.max(latlng.longitude, maxLng);
    }

    minLatLng = new LatLng(minLat, minLng);
    maxLatLng = new LatLng(maxLat, maxLng);

    LatLngBounds latlngBounds = new LatLngBounds(minLatLng, maxLatLng);

    return latlngBounds;
}
项目:geohashdroid    文件:SelectAGraticuleMode.java   
private void zoomToPoint(LatLng newPoint) {
    // Zoom in as need be, cover an area of a couple graticules in any
    // direction, leaving space for the graticule picker on the bottom of
    // the screen.
    LatLngBounds.Builder builder = LatLngBounds.builder();
    LatLng point = new LatLng(newPoint.latitude - CLOSENESS_Y_DOWN, newPoint.longitude - CLOSENESS_X);
    builder.include(point);

    point = new LatLng(newPoint.latitude - CLOSENESS_Y_DOWN, newPoint.longitude + CLOSENESS_X);
    builder.include(point);

    point = new LatLng(newPoint.latitude + CLOSENESS_Y_UP, newPoint.longitude + CLOSENESS_X);
    builder.include(point);

    point = new LatLng(newPoint.latitude + CLOSENESS_Y_UP, newPoint.longitude - CLOSENESS_X);
    builder.include(point);

    mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0));
}
项目:geohashdroid    文件:ExpeditionMode.java   
private void zoomToIdeal(Location current) {
    // We can't do an ideal zoom if we don't have permissions!
    if(arePermissionsDenied()) {
        Log.i(DEBUG_TAG, "Tried to do an ideal zoom after permissions were denied, ignoring...");
        return;
    }

    // Where "current" means the user's current location, and we're zooming
    // relative to the final destination, if we have it yet.  Let's check
    // that latter part first.
    if(mCurrentInfo == null) {
        Log.i(DEBUG_TAG, "zoomToIdeal was called before an Info was set, ignoring...");
        return;
    }

    // As a side note, yes, I COULD probably mash this all down to one line,
    // but I want this to be readable later without headaches.
    LatLngBounds bounds = LatLngBounds.builder()
            .include(new LatLng(current.getLatitude(), current.getLongitude()))
            .include(mCurrentInfo.getFinalDestinationLatLng())
            .build();

    CameraUpdate cam = CameraUpdateFactory.newLatLngBounds(bounds, mCentralMap.getResources().getDimensionPixelSize(R.dimen.map_zoom_padding));

    mMap.animateCamera(cam);
}
项目:geohashdroid    文件:ExpeditionMode.java   
private void zoomToInitialCurrentLocation(Location loc) {
    // This is called during initial lookup, just to make sure the map's at
    // a location OTHER than dead zero while we potentially wait for a stock
    // value to come in.  The zoom will be to half a degree around the
    // current point, just to grab an entire graticule's space.
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    builder.include(new LatLng(loc.getLatitude() - .5, loc.getLongitude() - .5));
    builder.include(new LatLng(loc.getLatitude() - .5, loc.getLongitude() + .5));
    builder.include(new LatLng(loc.getLatitude() + .5, loc.getLongitude() - .5));
    builder.include(new LatLng(loc.getLatitude() + .5, loc.getLongitude() + .5));
    CameraUpdate cam = CameraUpdateFactory.newLatLngBounds(builder.build(), mCentralMap.getResources().getDimensionPixelSize(R.dimen.map_zoom_padding));
    try {
        // And don't worry, when the stock comes in, that'll fire off a new
        // animateCamera() call, which in turn will cancel this one.
        mMap.animateCamera(cam);
    } catch(IllegalStateException ise) {
        // I really hope it's ready to go by now...
        Log.w(DEBUG_TAG, "The map isn't ready for animating yet!");
    }
}
项目:neo4art    文件:PluginMap.java   
/**
 * Return the visible region of the map
 * Thanks @fschmidt
 */
@SuppressWarnings("unused")
private void getVisibleRegion(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
  VisibleRegion visibleRegion = map.getProjection().getVisibleRegion();
  LatLngBounds latLngBounds = visibleRegion.latLngBounds;
  JSONObject result = new JSONObject();
  JSONObject northeast = new JSONObject();
  JSONObject southwest = new JSONObject();
  northeast.put("lat", latLngBounds.northeast.latitude);
  northeast.put("lng", latLngBounds.northeast.longitude);
  southwest.put("lat", latLngBounds.southwest.latitude);
  southwest.put("lng", latLngBounds.southwest.longitude);
  result.put("northeast", northeast);
  result.put("southwest", southwest);

  JSONArray latLngArray = new JSONArray();
  latLngArray.put(northeast);
  latLngArray.put(southwest);
  result.put("latLngArray", latLngArray);

  callbackContext.success(result);
}
项目:neo4art    文件:PluginMap.java   
/**
 * Return the visible region of the map
 * Thanks @fschmidt
 */
@SuppressWarnings("unused")
private void getVisibleRegion(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
  VisibleRegion visibleRegion = map.getProjection().getVisibleRegion();
  LatLngBounds latLngBounds = visibleRegion.latLngBounds;
  JSONObject result = new JSONObject();
  JSONObject northeast = new JSONObject();
  JSONObject southwest = new JSONObject();
  northeast.put("lat", latLngBounds.northeast.latitude);
  northeast.put("lng", latLngBounds.northeast.longitude);
  southwest.put("lat", latLngBounds.southwest.latitude);
  southwest.put("lng", latLngBounds.southwest.longitude);
  result.put("northeast", northeast);
  result.put("southwest", southwest);

  JSONArray latLngArray = new JSONArray();
  latLngArray.put(northeast);
  latLngArray.put(southwest);
  result.put("latLngArray", latLngArray);

  callbackContext.success(result);
}
项目:libertacao-android    文件:EditEventActivity.java   
/**
 * Pick place
 * https://medium.com/@hitherejoe/exploring-play-services-place-picker-autocomplete-150809f739fe
 */
@Override
public void onPickEventPlaceClick() {
    PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
    if(editEventDataModel.getEvent().hasLocation()) {
        double longitude = editEventDataModel.getEvent().getLongitude();
        double latitude = editEventDataModel.getEvent().getLatitude();
        double offset = 0.01;
        LatLng southwest = new LatLng(latitude - offset, longitude - offset);
        LatLng northeast = new LatLng(latitude + offset, longitude + offset);
        intentBuilder.setLatLngBounds(new LatLngBounds(southwest, northeast));
    }
    try {
        startActivityForResult(intentBuilder.build(this), PLACE_PICKER_REQUEST_CODE);
    } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
        Toast.makeText(this, getString(R.string.unknown_error), Toast.LENGTH_LONG).show();
    }
}
项目:KeepOn    文件:AbstractMapActivity.java   
protected void drawPolyline(List<Location> locationList) {
    // add polyline to map + calculate bounding box
    googleMap.clear();

    PolylineOptions polylineOptions = new PolylineOptions();
    LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();

    for (Location location : locationList) {
        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
        polylineOptions.add(latLng);
        boundsBuilder.include(latLng);
    }

    googleMap.addPolyline(polylineOptions
            .width(5)
            .color(Color.BLUE));

    int padding = (int) getResources().getDimension(R.dimen.map_bounds_padding);
    googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(boundsBuilder.build(), padding));
}
项目:RideOut    文件:PlaybackOverviewFragment.java   
@Override
protected void onPostExecute(Integer numRides) {
    if ( numRides > 0 ){
        //Post markers on map and add their positions to the LatLngBounds.Builder
        LatLngBounds.Builder bounds = new LatLngBounds.Builder();
        for (MarkerOptions options : markerOptionses){
            rideMarkers.add( mMap.addMarker(options));
            bounds.include(options.getPosition());
        }

        // Animate camera to the marker locations
        mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(),50));

    } else{
        Toast.makeText(getActivity().getApplicationContext(),
                "No ride data found", Toast.LENGTH_SHORT).show();
    }
}
项目:AndroidMapTest    文件:MapsActivity.java   
private void zoomToPoints() {
    try {


        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        //        for (Marker marker : markers) {
        builder.include(myLatLng);
        builder.include(shopLatLng);
        //        }
        LatLngBounds bounds = builder.build();

        int padding = 50; // offset from edges of the map in pixels
        CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);

        mMap.animateCamera(cu);
    }
    catch (Exception e)
    {
        ///possible error:
        /// java.lang.NullPointerException: Attempt to invoke interface method 'org.w3c.dom.NodeList org.w3c.dom.Document.getElementsByTagName(java.lang.String)' on a null object reference
    }
}
项目:neo4art    文件:PluginPolygon.java   
/**
 * Set points
 * @param args
 * @param callbackContext
 * @throws JSONException
 */
@SuppressWarnings("unused")
private void setPoints(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
  String id = args.getString(1);
  Polygon polygon = this.getPolygon(id);

  JSONArray points = args.getJSONArray(2);
  List<LatLng> path = PluginUtil.JSONArray2LatLngList(points);
  polygon.setPoints(path);

  LatLngBounds.Builder builder = new LatLngBounds.Builder();
  for (int i = 0; i < path.size(); i++) {
    builder.include(path.get(i));
  }
  this.objects.put("polygon_bounds_" + polygon.getId(), builder.build());
  this.sendNoResult(callbackContext);
}
项目:passarola    文件:MapsActivity.java   
private void showMarkers(List<PlaceViewModel> places) {
    if (googleMap != null && !places.isEmpty()) {
        LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
        for (PlaceViewModel placeViewModel : places) {
            Marker marker = googleMap.addMarker(createMarkerOption(placeViewModel));
            boundsBuilder.include(marker.getPosition());
            markersMap.put(placeViewModel.getLatLng(), new Pair<>(placeViewModel, marker));
        }
        LatLngBounds bounds = boundsBuilder.build();
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 160);
        googleMap.animateCamera(cameraUpdate);

    } else {
        onPlacesErrorEvent(new Exception("Google map is not instantiated"));
    }
}