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