use of com.google.android.libraries.maps.GoogleMap in project android-samples by googlemaps.
the class PolygonDemoActivity method onMapReady.
@Override
public void onMapReady(GoogleMap map) {
// Override the default content description on the view, for accessibility mode.
map.setContentDescription(getString(R.string.polygon_demo_description));
int fillColorArgb = Color.HSVToColor(fillAlphaBar.getProgress(), new float[] { fillHueBar.getProgress(), 1, 1 });
int strokeColorArgb = Color.HSVToColor(strokeAlphaBar.getProgress(), new float[] { strokeHueBar.getProgress(), 1, 1 });
// Create a rectangle with two rectangular holes.
mutablePolygon = map.addPolygon(new PolygonOptions().addAll(createRectangle(CENTER, 5, 5)).addHole(createRectangle(new LatLng(-22, 128), 1, 1)).addHole(createRectangle(new LatLng(-18, 133), 0.5, 1.5)).fillColor(fillColorArgb).strokeColor(strokeColorArgb).strokeWidth(strokeWidthBar.getProgress()).clickable(clickabilityCheckbox.isChecked()));
fillHueBar.setOnSeekBarChangeListener(this);
fillAlphaBar.setOnSeekBarChangeListener(this);
strokeWidthBar.setOnSeekBarChangeListener(this);
strokeHueBar.setOnSeekBarChangeListener(this);
strokeAlphaBar.setOnSeekBarChangeListener(this);
strokeJointTypeSpinner.setOnItemSelectedListener(this);
strokePatternSpinner.setOnItemSelectedListener(this);
mutablePolygon.setStrokeJointType(getSelectedJointType(strokeJointTypeSpinner.getSelectedItemPosition()));
mutablePolygon.setStrokePattern(getSelectedPattern(strokePatternSpinner.getSelectedItemPosition()));
// Move the map so that it is centered on the mutable polygon.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(CENTER, 4));
// Add a listener for polygon clicks that changes the clicked polygon's stroke color.
map.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
@Override
public void onPolygonClick(Polygon polygon) {
// Flip the red, green and blue components of the polygon's stroke color.
polygon.setStrokeColor(polygon.getStrokeColor() ^ 0x00ffffff);
}
});
}
use of com.google.android.libraries.maps.GoogleMap in project android-samples by googlemaps.
the class SplitStreetViewPanoramaAndMapDemoActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.split_street_view_panorama_and_map_demo);
final LatLng markerPosition;
if (savedInstanceState == null) {
markerPosition = SYDNEY;
} else {
markerPosition = savedInstanceState.getParcelable(MARKER_POSITION_KEY);
}
SupportStreetViewPanoramaFragment streetViewPanoramaFragment = (SupportStreetViewPanoramaFragment) getSupportFragmentManager().findFragmentById(R.id.streetviewpanorama);
streetViewPanoramaFragment.getStreetViewPanoramaAsync(new OnStreetViewPanoramaReadyCallback() {
@Override
public void onStreetViewPanoramaReady(StreetViewPanorama panorama) {
streetViewPanorama = panorama;
streetViewPanorama.setOnStreetViewPanoramaChangeListener(SplitStreetViewPanoramaAndMapDemoActivity.this);
// its state.
if (savedInstanceState == null) {
streetViewPanorama.setPosition(SYDNEY);
}
}
});
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap map) {
map.setOnMarkerDragListener(SplitStreetViewPanoramaAndMapDemoActivity.this);
// Creates a draggable marker. Long press to drag.
marker = map.addMarker(new MarkerOptions().position(markerPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.pegman)).draggable(true));
}
});
}
use of com.google.android.libraries.maps.GoogleMap in project android-maps-utils by googlemaps.
the class HeatmapsPlacesDemoActivity method startDemo.
@Override
protected void startDemo(boolean isRestore) {
EditText editText = findViewById(R.id.input_text);
editText.setOnEditorActionListener((textView, actionId, keyEvent) -> {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_GO) {
submit(null);
handled = true;
}
return handled;
});
mCheckboxLayout = findViewById(R.id.checkboxes);
GoogleMap map = getMap();
if (!isRestore) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 11));
}
// Add a circle around Sydney to roughly encompass the results
map.addCircle(new CircleOptions().center(SYDNEY).radius(SEARCH_RADIUS * 1.2).strokeColor(Color.RED).strokeWidth(4));
}
use of com.google.android.libraries.maps.GoogleMap in project android-maps-utils by googlemaps.
the class PolySimplifyDemoActivity method startDemo.
@Override
protected void startDemo(boolean isRestore) {
GoogleMap map = getMap();
// Original line
List<LatLng> line = PolyUtil.decode(LINE);
map.addPolyline(new PolylineOptions().addAll(line).color(Color.BLACK));
if (!isRestore) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.05870, -82.4090), 15));
}
List<LatLng> simplifiedLine;
/*
* Simplified lines - increasing the tolerance will result in fewer points in the simplified
* line
*/
// meters
double tolerance = 5;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.RED - ALPHA_ADJUSTMENT));
// meters
tolerance = 20;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.GREEN - ALPHA_ADJUSTMENT));
// meters
tolerance = 50;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.MAGENTA - ALPHA_ADJUSTMENT));
// meters
tolerance = 500;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.YELLOW - ALPHA_ADJUSTMENT));
// meters
tolerance = 1000;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.BLUE - ALPHA_ADJUSTMENT));
// Triangle polygon - the polygon should be closed
ArrayList<LatLng> triangle = new ArrayList<>();
// Should match last point
triangle.add(new LatLng(28.06025, -82.41030));
triangle.add(new LatLng(28.06129, -82.40945));
triangle.add(new LatLng(28.06206, -82.40917));
triangle.add(new LatLng(28.06125, -82.40850));
triangle.add(new LatLng(28.06035, -82.40834));
triangle.add(new LatLng(28.06038, -82.40924));
// Should match first point
triangle.add(new LatLng(28.06025, -82.41030));
map.addPolygon(new PolygonOptions().addAll(triangle).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
// Simplified triangle polygon
// meters
tolerance = 88;
List simplifiedTriangle = PolyUtil.simplify(triangle, tolerance);
map.addPolygon(new PolygonOptions().addAll(simplifiedTriangle).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
// Oval polygon - the polygon should be closed
List<LatLng> oval = PolyUtil.decode(OVAL_POLYGON);
map.addPolygon(new PolygonOptions().addAll(oval).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
// Simplified oval polygon
// meters
tolerance = 10;
List simplifiedOval = PolyUtil.simplify(oval, tolerance);
map.addPolygon(new PolygonOptions().addAll(simplifiedOval).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
}
Aggregations