Search in sources :

Example 26 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project open-event-android by fossasia.

the class MapsFragment method showLocationsOnMap.

private void showLocationsOnMap() {
    String locationName;
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    if (mLocations == null || mLocations.isEmpty())
        return;
    // Add search names for all locations
    for (MicrolocationClusterWrapper microlocation : mLocations) {
        locationName = microlocation.getMicrolocation().getName();
        searchItems.add(locationName);
        stringMicrolocationClusterWrapperMap.put(locationName, microlocation);
        builder.include(microlocation.getPosition());
    }
    // Set max zoom level so that all marker are visible
    LatLngBounds bounds = builder.build();
    final CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, Math.round(Utils.dpToPx(40)));
    try {
        mMap.moveCamera(cameraUpdate);
    } catch (IllegalStateException ise) {
        mMap.setOnMapLoadedCallback(() -> mMap.moveCamera(cameraUpdate));
    }
    if (fragmentLocationName != null)
        clusterRenderer.focusOnMarkers(stringMicrolocationClusterWrapperMap.get(fragmentLocationName));
    if (searchView == null || mSearchAutoComplete == null)
        return;
    ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, searchItems);
    mSearchAutoComplete.setAdapter(adapter);
    mSearchAutoComplete.setOnItemClickListener((parent, view, position, id) -> {
        String loc = adapter.getItem(position);
        clusterRenderer.focusOnMarkers(stringMicrolocationClusterWrapperMap.get(loc));
        searchView.clearFocus();
        View mapView = getActivity().getCurrentFocus();
        if (mapView != null) {
            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mapView.getWindowToken(), 0);
        }
    });
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) InputMethodManager(android.view.inputmethod.InputMethodManager) CameraUpdate(com.google.android.gms.maps.CameraUpdate) SearchView(android.support.v7.widget.SearchView) View(android.view.View) ArrayAdapter(android.widget.ArrayAdapter)

Example 27 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method getLatLngBounds.

private LatLngBounds getLatLngBounds(LatLng center, double radius) {
    LatLng southwest = SphericalUtil.computeOffset(center, radius * Math.sqrt(2.0), 225);
    LatLng northeast = SphericalUtil.computeOffset(center, radius * Math.sqrt(2.0), 45);
    return new LatLngBounds(southwest, northeast);
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) LatLng(com.google.android.gms.maps.model.LatLng)

Example 28 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method getAutocompletePredictions.

@ReactMethod
public void getAutocompletePredictions(String query, ReadableMap options, final Promise promise) {
    String type = options.getString("type");
    String country = options.getString("country");
    country = country.isEmpty() ? null : country;
    double latitude = options.getDouble("latitude");
    double longitude = options.getDouble("longitude");
    double radius = options.getDouble("radius");
    LatLng center = new LatLng(latitude, longitude);
    LatLngBounds bounds = null;
    if (latitude != 0 && longitude != 0 && radius != 0) {
        bounds = this.getLatLngBounds(center, radius);
    }
    PendingResult<AutocompletePredictionBuffer> results = Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, query, bounds, getFilterType(type, country));
    AutocompletePredictionBuffer autocompletePredictions = results.await(60, TimeUnit.SECONDS);
    final Status status = autocompletePredictions.getStatus();
    if (status.isSuccess()) {
        if (autocompletePredictions.getCount() == 0) {
            WritableArray emptyResult = Arguments.createArray();
            autocompletePredictions.release();
            promise.resolve(emptyResult);
            return;
        }
        WritableArray predictionsList = Arguments.createArray();
        for (AutocompletePrediction prediction : autocompletePredictions) {
            WritableMap map = Arguments.createMap();
            map.putString("fullText", prediction.getFullText(null).toString());
            map.putString("primaryText", prediction.getPrimaryText(null).toString());
            map.putString("secondaryText", prediction.getSecondaryText(null).toString());
            map.putString("placeID", prediction.getPlaceId().toString());
            if (prediction.getPlaceTypes() != null) {
                List<String> types = new ArrayList<>();
                for (Integer placeType : prediction.getPlaceTypes()) {
                    types.add(findPlaceTypeLabelByPlaceTypeId(placeType));
                }
                map.putArray("types", Arguments.fromArray(types.toArray(new String[0])));
            }
            predictionsList.pushMap(map);
        }
        // Release the buffer now that all data has been copied.
        autocompletePredictions.release();
        promise.resolve(predictionsList);
    } else {
        Log.i(TAG, "Error making autocomplete prediction API call: " + status.toString());
        autocompletePredictions.release();
        promise.reject("E_AUTOCOMPLETE_ERROR", new Error("Error making autocomplete prediction API call: " + status.toString()));
        return;
    }
}
Also used : Status(com.google.android.gms.common.api.Status) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) AutocompletePredictionBuffer(com.google.android.gms.location.places.AutocompletePredictionBuffer) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) ArrayList(java.util.ArrayList) AutocompletePrediction(com.google.android.gms.location.places.AutocompletePrediction) LatLng(com.google.android.gms.maps.model.LatLng) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 29 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project zendrive-sdk-android-sample by zendrive.

the class MapActivity method drawTripOnMap.

public void drawTripOnMap(final DriveInfo driveInfo) {
    // draw trip details on map.
    final List<LatLng> points = new ArrayList<>();
    final LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (LocationPointWithTimestamp pt : driveInfo.waypoints) {
        LatLng latLng = new LatLng(pt.location.latitude, pt.location.longitude);
        // Adding the taped point to the ArrayList
        points.add(latLng);
        builder.include(latLng);
    }
    final LatLngBounds bounds = builder.build();
    supportmapfragment.getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(GoogleMap gMap) {
            PolylineOptions polylineOptions = new PolylineOptions();
            // Setting the color of the polyline
            polylineOptions.color(Color.RED);
            // Setting the width of the polyline
            polylineOptions.width(10);
            polylineOptions.addAll(points);
            gMap.addPolyline(polylineOptions);
            // offset from edges of the map in pixels
            int padding = 100;
            CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
            gMap.animateCamera(cu);
            // mark trip start and trip end.
            if (!points.isEmpty()) {
                LatLng tripStartLocation = points.get(0);
                LatLng tripEndLocation = points.get(points.size() - 1);
                markPoint(gMap, tripStartLocation, BitmapDescriptorFactory.HUE_GREEN, "Trip Start");
                markPoint(gMap, tripEndLocation, BitmapDescriptorFactory.HUE_GREEN, "Trip End");
            }
            // mark events.
            markEvents(gMap, driveInfo.events);
        }
    });
}
Also used : LocationPointWithTimestamp(com.zendrive.sdk.LocationPointWithTimestamp) GoogleMap(com.google.android.gms.maps.GoogleMap) ArrayList(java.util.ArrayList) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) OnMapReadyCallback(com.google.android.gms.maps.OnMapReadyCallback) LatLng(com.google.android.gms.maps.model.LatLng) CameraUpdate(com.google.android.gms.maps.CameraUpdate) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions)

Example 30 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project NavitiaSDKUX_android by CanalTP.

the class JourneyMapViewComponentSpec method zoomToPolyline.

private static void zoomToPolyline(GoogleMap googleMap, List<LatLng> polylineCoords, boolean animated) {
    int mapPadding = 180;
    LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
    for (LatLng latLngPoint : polylineCoords) {
        boundsBuilder.include(latLngPoint);
    }
    LatLngBounds latLngBounds = boundsBuilder.build();
    if (animated) {
        googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, mapPadding));
    } else {
        googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, mapPadding));
    }
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) LatLng(com.google.android.gms.maps.model.LatLng)

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