use of com.google.android.gms.maps.model.LatLngBounds in project Android-ReactiveLocation by mcharmas.
the class PlacesActivity method onLocationPermissionGranted.
@Override
protected void onLocationPermissionGranted() {
compositeSubscription = new CompositeSubscription();
compositeSubscription.add(reactiveLocationProvider.getCurrentPlace(null).subscribe(new Action1<PlaceLikelihoodBuffer>() {
@Override
public void call(PlaceLikelihoodBuffer buffer) {
PlaceLikelihood likelihood = buffer.get(0);
if (likelihood != null) {
currentPlaceView.setText(likelihood.getPlace().getName());
}
buffer.release();
}
}));
Observable<String> queryObservable = RxTextView.textChanges(queryView).map(new Func1<CharSequence, String>() {
@Override
public String call(CharSequence charSequence) {
return charSequence.toString();
}
}).debounce(1, TimeUnit.SECONDS).filter(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
return !TextUtils.isEmpty(s);
}
});
Observable<Location> lastKnownLocationObservable = reactiveLocationProvider.getLastKnownLocation();
Observable<AutocompletePredictionBuffer> suggestionsObservable = Observable.combineLatest(queryObservable, lastKnownLocationObservable, new Func2<String, Location, QueryWithCurrentLocation>() {
@Override
public QueryWithCurrentLocation call(String query, Location currentLocation) {
return new QueryWithCurrentLocation(query, currentLocation);
}
}).flatMap(new Func1<QueryWithCurrentLocation, Observable<AutocompletePredictionBuffer>>() {
@Override
public Observable<AutocompletePredictionBuffer> call(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);
}
});
compositeSubscription.add(suggestionsObservable.subscribe(new Action1<AutocompletePredictionBuffer>() {
@Override
public void call(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 coins-android by bubelov.
the class MapActivity method refreshMap.
private void refreshMap() {
if (map == null) {
return;
}
LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
Collection<Place> places = placesRepository.getPlaces(bounds);
placesManager.clearItems();
placesManager.addItems(toPlaceMarkers(places));
placesManager.cluster();
}
use of com.google.android.gms.maps.model.LatLngBounds in project wigle-wifi-wardriving by wiglenet.
the class GeoJsonParser method parseFeature.
/**
* Parses a single GeoJSON feature which contains a geometry and properties member both of
* which can be null. Also parses the bounding box and id members of the feature if they exist.
*
* @param geoJsonFeature feature to parse
* @return GeoJsonFeature object
*/
private static GeoJsonFeature parseFeature(JSONObject geoJsonFeature) {
String id = null;
LatLngBounds boundingBox = null;
GeoJsonGeometry geometry = null;
HashMap<String, String> properties = new HashMap<String, String>();
try {
if (geoJsonFeature.has(FEATURE_ID)) {
id = geoJsonFeature.getString(FEATURE_ID);
}
if (geoJsonFeature.has(BOUNDING_BOX)) {
boundingBox = parseBoundingBox(geoJsonFeature.getJSONArray(BOUNDING_BOX));
}
if (geoJsonFeature.has(FEATURE_GEOMETRY) && !geoJsonFeature.isNull(FEATURE_GEOMETRY)) {
geometry = parseGeometry(geoJsonFeature.getJSONObject(FEATURE_GEOMETRY));
}
if (geoJsonFeature.has(PROPERTIES) && !geoJsonFeature.isNull(PROPERTIES)) {
properties = parseProperties(geoJsonFeature.getJSONObject("properties"));
}
} catch (JSONException e) {
Log.w(LOG_TAG, "Feature could not be successfully parsed " + geoJsonFeature.toString());
return null;
}
return new GeoJsonFeature(geometry, id, properties, boundingBox);
}
use of com.google.android.gms.maps.model.LatLngBounds in project wigle-wifi-wardriving by wiglenet.
the class KmlFeatureParser method createLatLngBounds.
/**
* Given a set of four latLng coordinates, creates a LatLng Bound
*
* @param north North coordinate of the bounding box
* @param south South coordinate of the bounding box
* @param east East coordinate of the bounding box
* @param west West coordinate of the bounding box
*/
private static LatLngBounds createLatLngBounds(Double north, Double south, Double east, Double west) {
LatLng southWest = new LatLng(south, west);
LatLng northEast = new LatLng(north, east);
return new LatLngBounds(southWest, northEast);
}
use of com.google.android.gms.maps.model.LatLngBounds in project hypertrack-live-android by hypertrack.
the class Home method updateMapView.
private void updateMapView() {
if (mMap == null || !isMapLoaded) {
return;
}
if (currentLocationMarker == null && expectedPlace == null) {
return;
}
LatLngBounds.Builder builder = new LatLngBounds.Builder();
if (currentLocationMarker != null) {
LatLng current = currentLocationMarker.getPosition();
builder.include(current);
}
if (expectedPlace != null && expectedPlace.getLocation() != null && expectedPlace.getLocation().getLatLng() != null) {
LatLng destination = expectedPlace.getLocation().getLatLng();
builder.include(destination);
}
LatLngBounds bounds = builder.build();
try {
CameraUpdate cameraUpdate;
if (expectedPlace != null && currentLocationMarker != null) {
int width = getResources().getDisplayMetrics().widthPixels;
int height = getResources().getDisplayMetrics().heightPixels;
int padding = (int) (width * 0.12);
cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding);
} else {
LatLng latLng = currentLocationMarker != null ? currentLocationMarker.getPosition() : expectedPlace.getLocation().getLatLng();
cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, zoomLevel);
}
mMap.animateCamera(cameraUpdate, 1000, null);
} catch (Exception e) {
e.printStackTrace();
Crashlytics.logException(e);
}
}
Aggregations