Search in sources :

Example 1 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() {
    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));
        }
    }));
}
Also used : PlaceLikelihoodBuffer(com.google.android.gms.location.places.PlaceLikelihoodBuffer) AutocompletePredictionBuffer(com.google.android.gms.location.places.AutocompletePredictionBuffer) ArrayList(java.util.ArrayList) LatLng(com.google.android.gms.maps.model.LatLng) Func2(rx.functions.Func2) Action1(rx.functions.Action1) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) Observable(rx.Observable) CompositeSubscription(rx.subscriptions.CompositeSubscription) AutocompletePrediction(com.google.android.gms.location.places.AutocompletePrediction) PlaceLikelihood(com.google.android.gms.location.places.PlaceLikelihood) Location(android.location.Location)

Example 2 with LatLngBounds

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();
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) Place(com.bubelov.coins.model.Place)

Example 3 with LatLngBounds

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);
}
Also used : HashMap(java.util.HashMap) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) JSONException(org.json.JSONException)

Example 4 with LatLngBounds

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

Example 5 with LatLngBounds

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);
    }
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) LatLng(com.google.android.gms.maps.model.LatLng) CameraUpdate(com.google.android.gms.maps.CameraUpdate) SuppressLint(android.annotation.SuppressLint) ActivityNotFoundException(android.content.ActivityNotFoundException)

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