Search in sources :

Example 1 with GoogleMap

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);
        }
    });
}
Also used : PolygonOptions(com.google.android.libraries.maps.model.PolygonOptions) GoogleMap(com.google.android.libraries.maps.GoogleMap) LatLng(com.google.android.libraries.maps.model.LatLng) Polygon(com.google.android.libraries.maps.model.Polygon)

Example 2 with GoogleMap

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));
        }
    });
}
Also used : SupportMapFragment(com.google.android.libraries.maps.SupportMapFragment) StreetViewPanorama(com.google.android.libraries.maps.StreetViewPanorama) MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) OnStreetViewPanoramaReadyCallback(com.google.android.libraries.maps.OnStreetViewPanoramaReadyCallback) GoogleMap(com.google.android.libraries.maps.GoogleMap) OnMapReadyCallback(com.google.android.libraries.maps.OnMapReadyCallback) LatLng(com.google.android.libraries.maps.model.LatLng) SupportStreetViewPanoramaFragment(com.google.android.libraries.maps.SupportStreetViewPanoramaFragment)

Example 3 with GoogleMap

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));
}
Also used : EditText(android.widget.EditText) CircleOptions(com.google.android.libraries.maps.model.CircleOptions) GoogleMap(com.google.android.libraries.maps.GoogleMap)

Example 4 with GoogleMap

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));
}
Also used : GoogleMap(com.google.android.libraries.maps.GoogleMap) PolygonOptions(com.google.android.libraries.maps.model.PolygonOptions) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LatLng(com.google.android.libraries.maps.model.LatLng) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions)

Aggregations

GoogleMap (com.google.android.libraries.maps.GoogleMap)4 LatLng (com.google.android.libraries.maps.model.LatLng)3 PolygonOptions (com.google.android.libraries.maps.model.PolygonOptions)2 EditText (android.widget.EditText)1 OnMapReadyCallback (com.google.android.libraries.maps.OnMapReadyCallback)1 OnStreetViewPanoramaReadyCallback (com.google.android.libraries.maps.OnStreetViewPanoramaReadyCallback)1 StreetViewPanorama (com.google.android.libraries.maps.StreetViewPanorama)1 SupportMapFragment (com.google.android.libraries.maps.SupportMapFragment)1 SupportStreetViewPanoramaFragment (com.google.android.libraries.maps.SupportStreetViewPanoramaFragment)1 CircleOptions (com.google.android.libraries.maps.model.CircleOptions)1 MarkerOptions (com.google.android.libraries.maps.model.MarkerOptions)1 Polygon (com.google.android.libraries.maps.model.Polygon)1 PolylineOptions (com.google.android.libraries.maps.model.PolylineOptions)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1