Search in sources :

Example 16 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project Android-ReactiveLocation by mcharmas.

the class PlacesActivity method onLocationPermissionGranted.

@Override
protected void onLocationPermissionGranted() {
    compositeDisposable = new CompositeDisposable();
    compositeDisposable.add(reactiveLocationProvider.getCurrentPlace(null).subscribe(new Consumer<PlaceLikelihoodBuffer>() {

        @Override
        public void accept(PlaceLikelihoodBuffer buffer) {
            PlaceLikelihood likelihood = buffer.get(0);
            if (likelihood != null) {
                currentPlaceView.setText(likelihood.getPlace().getName());
            }
            buffer.release();
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            Log.e("PlacesActivity", "Error in observable", throwable);
        }
    }));
    Observable<String> queryObservable = RxTextView.textChanges(queryView).map(new Function<CharSequence, String>() {

        @Override
        public String apply(CharSequence charSequence) {
            return charSequence.toString();
        }
    }).debounce(1, TimeUnit.SECONDS).filter(new Predicate<String>() {

        @Override
        public boolean test(String s) {
            return !TextUtils.isEmpty(s);
        }
    });
    Observable<Location> lastKnownLocationObservable = reactiveLocationProvider.getLastKnownLocation();
    Observable<AutocompletePredictionBuffer> suggestionsObservable = Observable.combineLatest(queryObservable, lastKnownLocationObservable, new BiFunction<String, Location, QueryWithCurrentLocation>() {

        @Override
        public QueryWithCurrentLocation apply(String query, Location currentLocation) {
            return new QueryWithCurrentLocation(query, currentLocation);
        }
    }).flatMap(new Function<QueryWithCurrentLocation, Observable<AutocompletePredictionBuffer>>() {

        @Override
        public Observable<AutocompletePredictionBuffer> apply(QueryWithCurrentLocation q) {
            if (q.location == null)
                return Observable.empty();
            double latitude = q.location.getLatitude();
            double longitude = q.location.getLongitude();
            LatLngBounds bounds = new LatLngBounds(new LatLng(latitude - 0.05, longitude - 0.05), new LatLng(latitude + 0.05, longitude + 0.05));
            return reactiveLocationProvider.getPlaceAutocompletePredictions(q.query, bounds, null);
        }
    });
    compositeDisposable.add(suggestionsObservable.subscribe(new Consumer<AutocompletePredictionBuffer>() {

        @Override
        public void accept(AutocompletePredictionBuffer buffer) {
            List<AutocompleteInfo> infos = new ArrayList<>();
            for (AutocompletePrediction prediction : buffer) {
                infos.add(new AutocompleteInfo(prediction.getFullText(null).toString(), prediction.getPlaceId()));
            }
            buffer.release();
            placeSuggestionsList.setAdapter(new ArrayAdapter<>(PlacesActivity.this, android.R.layout.simple_list_item_1, infos));
        }
    }));
}
Also used : PlaceLikelihoodBuffer(com.google.android.gms.location.places.PlaceLikelihoodBuffer) AutocompletePredictionBuffer(com.google.android.gms.location.places.AutocompletePredictionBuffer) ArrayList(java.util.ArrayList) Consumer(io.reactivex.functions.Consumer) LatLng(com.google.android.gms.maps.model.LatLng) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) Observable(io.reactivex.Observable) BiFunction(io.reactivex.functions.BiFunction) AutocompletePrediction(com.google.android.gms.location.places.AutocompletePrediction) PlaceLikelihood(com.google.android.gms.location.places.PlaceLikelihood) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Location(android.location.Location)

Example 17 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project android-maps-utils by googlemaps.

the class GeoJsonParser method parseBoundingBox.

/**
 * 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);
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) LatLng(com.google.android.gms.maps.model.LatLng)

Example 18 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project collect by opendatakit.

the class GoogleMapFragment method zoomToBoundingBox.

@Override
public void zoomToBoundingBox(Iterable<MapPoint> points, double scaleFactor, boolean animate) {
    if (map == null) {
        // during Robolectric tests, map will be null
        return;
    }
    if (points != null) {
        int count = 0;
        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        MapPoint lastPoint = null;
        for (MapPoint point : points) {
            lastPoint = point;
            builder.include(toLatLng(point));
            count++;
        }
        if (count == 1) {
            zoomToPoint(lastPoint, animate);
        } else if (count > 1) {
            final LatLngBounds bounds = expandBounds(builder.build(), 1 / scaleFactor);
            new Handler().postDelayed(() -> {
                moveOrAnimateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0), animate);
            }, 100);
        }
    }
}
Also used : MapPoint(org.odk.collect.geo.maps.MapPoint) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) Handler(android.os.Handler) MapPoint(org.odk.collect.geo.maps.MapPoint) SuppressLint(android.annotation.SuppressLint)

Example 19 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project collect by opendatakit.

the class GoogleMapsMapBoxOfflineTileProvider method calculateBounds.

private void calculateBounds() {
    if (this.isDatabaseAvailable()) {
        String[] projection = { "value" };
        String[] subArgs = { "bounds" };
        Cursor c = this.database.query("metadata", projection, "name = ?", subArgs, null, null, null);
        c.moveToFirst();
        if (!c.isAfterLast()) {
            String[] parts = c.getString(0).split(",\\s*");
            double w = Double.parseDouble(parts[0]);
            double s = Double.parseDouble(parts[1]);
            double e = Double.parseDouble(parts[2]);
            double n = Double.parseDouble(parts[3]);
            LatLng ne = new LatLng(n, e);
            LatLng sw = new LatLng(s, w);
            this.bounds = new LatLngBounds(sw, ne);
        }
        c.close();
    }
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) LatLng(com.google.android.gms.maps.model.LatLng) Cursor(android.database.Cursor)

Example 20 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project collect by opendatakit.

the class GoogleMapsMapBoxOfflineTileProvider method calculateBounds.

private void calculateBounds() {
    if (this.isDatabaseAvailable()) {
        String[] projection = new String[] { "value" };
        String[] subArgs = new String[] { "bounds" };
        Cursor c = this.database.query("metadata", projection, "name = ?", subArgs, null, null, null);
        c.moveToFirst();
        if (!c.isAfterLast()) {
            String[] parts = c.getString(0).split(",\\s*");
            double w = Double.parseDouble(parts[0]);
            double s = Double.parseDouble(parts[1]);
            double e = Double.parseDouble(parts[2]);
            double n = Double.parseDouble(parts[3]);
            LatLng ne = new LatLng(n, e);
            LatLng sw = new LatLng(s, w);
            this.bounds = new LatLngBounds(sw, ne);
        }
        c.close();
    }
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) LatLng(com.google.android.gms.maps.model.LatLng) Cursor(android.database.Cursor)

Aggregations

LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)42 LatLng (com.google.android.gms.maps.model.LatLng)27 CameraUpdate (com.google.android.gms.maps.CameraUpdate)11 Marker (com.google.android.gms.maps.model.Marker)6 Intent (android.content.Intent)5 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)5 ArrayList (java.util.ArrayList)5 View (android.view.View)4 JSONException (org.json.JSONException)4 Handler (android.os.Handler)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 AutocompletePrediction (com.google.android.gms.location.places.AutocompletePrediction)3 AutocompletePredictionBuffer (com.google.android.gms.location.places.AutocompletePredictionBuffer)3 GoogleMap (com.google.android.gms.maps.GoogleMap)3 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)3 HashMap (java.util.HashMap)3 JSONObject (org.json.JSONObject)3 SuppressLint (android.annotation.SuppressLint)2 Cursor (android.database.Cursor)2