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));
}
}));
}
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);
}
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);
}
}
}
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();
}
}
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();
}
}
Aggregations