Search in sources :

Example 6 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions in project android-samples by googlemaps.

the class PolyActivity method onMapReady.

/**
 * Manipulates the map when it's available.
 * The API invokes this callback when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera.
 * In this tutorial, we add polylines and polygons to represent routes and areas on the map.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    // Add polylines to the map.
    // Polylines are useful to show a route or some other connection between points.
    Polyline polyline1 = googleMap.addPolyline(new PolylineOptions().clickable(true).add(new LatLng(-35.016, 143.321), new LatLng(-34.747, 145.592), new LatLng(-34.364, 147.891), new LatLng(-33.501, 150.217), new LatLng(-32.306, 149.248), new LatLng(-32.491, 147.309)));
    // Store a data object with the polyline, used here to indicate an arbitrary type.
    polyline1.setTag("A");
    // Style the polyline.
    stylePolyline(polyline1);
    Polyline polyline2 = googleMap.addPolyline(new PolylineOptions().clickable(true).add(new LatLng(-29.501, 119.700), new LatLng(-27.456, 119.672), new LatLng(-25.971, 124.187), new LatLng(-28.081, 126.555), new LatLng(-28.848, 124.229), new LatLng(-28.215, 123.938)));
    polyline2.setTag("B");
    stylePolyline(polyline2);
    // Add polygons to indicate areas on the map.
    Polygon polygon1 = googleMap.addPolygon(new PolygonOptions().clickable(true).add(new LatLng(-27.457, 153.040), new LatLng(-33.852, 151.211), new LatLng(-37.813, 144.962), new LatLng(-34.928, 138.599)));
    // Store a data object with the polygon, used here to indicate an arbitrary type.
    polygon1.setTag("alpha");
    // Style the polygon.
    stylePolygon(polygon1);
    Polygon polygon2 = googleMap.addPolygon(new PolygonOptions().clickable(true).add(new LatLng(-31.673, 128.892), new LatLng(-31.952, 115.857), new LatLng(-17.785, 122.258), new LatLng(-12.4258, 130.7932)));
    polygon2.setTag("beta");
    stylePolygon(polygon2);
    // Position the map's camera near Alice Springs in the center of Australia,
    // and set the zoom factor so most of Australia shows on the screen.
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-23.684, 133.903), 4));
    // Set listeners for click events.
    googleMap.setOnPolylineClickListener(this);
    googleMap.setOnPolygonClickListener(this);
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) Polyline(com.google.android.gms.maps.model.Polyline) LatLng(com.google.android.gms.maps.model.LatLng) Polygon(com.google.android.gms.maps.model.Polygon) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions)

Example 7 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions in project cw-omnibus by commonsguy.

the class MainActivity method onMapReady.

@Override
public void onMapReady(final GoogleMap map) {
    if (needsInit) {
        CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044, -73.98180484771729));
        CameraUpdate zoom = CameraUpdateFactory.zoomTo(15);
        map.moveCamera(center);
        map.animateCamera(zoom);
    }
    addMarker(map, 40.748963847316034, -73.96807193756104, R.string.un, R.string.united_nations);
    addMarker(map, 40.76866299974387, -73.98268461227417, R.string.lincoln_center, R.string.lincoln_center_snippet);
    addMarker(map, 40.765136435316755, -73.97989511489868, R.string.carnegie_hall, R.string.practice_x3);
    addMarker(map, 40.70686417491799, -74.01572942733765, R.string.downtown_club, R.string.heisman_trophy);
    PolylineOptions line = new PolylineOptions().add(new LatLng(40.70686417491799, -74.01572942733765), new LatLng(40.76866299974387, -73.98268461227417), new LatLng(40.765136435316755, -73.97989511489868), new LatLng(40.748963847316034, -73.96807193756104)).width(5).color(Color.RED);
    map.addPolyline(line);
    PolygonOptions area = new PolygonOptions().add(new LatLng(40.748429, -73.984573), new LatLng(40.753393, -73.996311), new LatLng(40.758393, -73.992705), new LatLng(40.753484, -73.980882)).strokeColor(Color.BLUE);
    map.addPolygon(area);
    map.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater()));
    map.setOnInfoWindowClickListener(this);
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) LatLng(com.google.android.gms.maps.model.LatLng) CameraUpdate(com.google.android.gms.maps.CameraUpdate) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions)

Example 8 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions in project collect by opendatakit.

the class GeoShapeGoogleMapActivity method clearFeatures.

private void clearFeatures() {
    map.clear();
    polygon = null;
    polygonOptions = new PolygonOptions();
    polygonOptions.strokeColor(Color.RED);
    polygonOptions.zIndex(1);
    markerArray.clear();
    map.setOnMapLongClickListener(this);
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions)

Example 9 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions in project collect by opendatakit.

the class GeoShapeGoogleMapActivity method setupMap.

private void setupMap(GoogleMap googleMap) {
    map = googleMap;
    if (map == null) {
        ToastUtils.showShortToast(R.string.google_play_services_error_occured);
        finish();
        return;
    }
    helper = new MapHelper(this, map);
    map.setMyLocationEnabled(true);
    map.setOnMapLongClickListener(this);
    map.setOnMarkerDragListener(this);
    map.getUiSettings().setMyLocationButtonEnabled(false);
    map.getUiSettings().setCompassEnabled(true);
    map.getUiSettings().setZoomControlsEnabled(false);
    polygonOptions = new PolygonOptions();
    polygonOptions.strokeColor(Color.RED);
    polygonOptions.zIndex(1);
    gpsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // if(curLocation !=null){
            // map.animateCamera(CameraUpdateFactory.newLatLngZoom(curlatLng,16));
            // }
            showZoomDialog();
        }
    });
    clearButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (markerArray.size() != 0) {
                showClearDialog();
            }
        }
    });
    ImageButton returnButton = findViewById(R.id.save);
    returnButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            returnLocation();
        }
    });
    Intent intent = getIntent();
    if (intent != null && intent.getExtras() != null) {
        if (intent.hasExtra(GeoShapeWidget.SHAPE_LOCATION)) {
            clearButton.setEnabled(true);
            String s = intent.getStringExtra(GeoShapeWidget.SHAPE_LOCATION);
            gpsButton.setEnabled(true);
            overlayIntentPolygon(s);
        }
    }
    ImageButton layersButton = findViewById(R.id.layers);
    layersButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            helper.showLayersDialog(GeoShapeGoogleMapActivity.this);
        }
    });
    zoomDialogView = getLayoutInflater().inflate(R.layout.geoshape_zoom_dialog, null);
    zoomLocationButton = zoomDialogView.findViewById(R.id.zoom_location);
    zoomLocationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (curLocation != null && curlatLng != null) {
                map.animateCamera(CameraUpdateFactory.newLatLngZoom(curlatLng, 17));
            }
            zoomDialog.dismiss();
        }
    });
    zoomPointButton = zoomDialogView.findViewById(R.id.zoom_shape);
    zoomPointButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // zoomToCentroid();
            zoomToBounds();
            zoomDialog.dismiss();
        }
    });
    // If there is a last know location go there
    if (curLocation != null) {
        curlatLng = new LatLng(curLocation.getLatitude(), curLocation.getLongitude());
        foundFirstLocation = true;
        gpsButton.setEnabled(true);
        showZoomDialog();
    }
    helper.setBasemap();
}
Also used : ImageButton(android.widget.ImageButton) PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) MapHelper(org.odk.collect.android.spatial.MapHelper) Intent(android.content.Intent) LatLng(com.google.android.gms.maps.model.LatLng) View(android.view.View)

Example 10 with PolygonOptions

use of com.google.android.gms.maps.model.PolygonOptions in project android-samples by googlemaps.

the class LiteDemoActivity method addPolyObjects.

/**
 * Add a Polyline and a Polygon to the map.
 * The Polyline connects Melbourne, Adelaide and Perth. The Polygon is located in the Northern
 * Territory (Australia).
 */
private void addPolyObjects() {
    mMap.addPolyline((new PolylineOptions()).add(MELBOURNE, ADELAIDE, PERTH).color(Color.GREEN).width(5f));
    mMap.addPolygon(new PolygonOptions().add(POLYGON).fillColor(Color.CYAN).strokeColor(Color.BLUE).strokeWidth(5));
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions)

Aggregations

PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)16 LatLng (com.google.android.gms.maps.model.LatLng)8 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)6 Polygon (com.google.android.gms.maps.model.Polygon)4 GoogleMap (com.google.android.gms.maps.GoogleMap)3 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)3 CameraUpdate (com.google.android.gms.maps.CameraUpdate)2 Polyline (com.google.android.gms.maps.model.Polyline)2 Intent (android.content.Intent)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 BitmapDescriptor (com.google.android.gms.maps.model.BitmapDescriptor)1 CircleOptions (com.google.android.gms.maps.model.CircleOptions)1 GroundOverlayOptions (com.google.android.gms.maps.model.GroundOverlayOptions)1 Marker (com.google.android.gms.maps.model.Marker)1 GeoJsonLineString (com.google.maps.android.data.geojson.GeoJsonLineString)1 GeoJsonMultiLineString (com.google.maps.android.data.geojson.GeoJsonMultiLineString)1 GeoJsonMultiPolygon (com.google.maps.android.data.geojson.GeoJsonMultiPolygon)1 GeoJsonPolygon (com.google.maps.android.data.geojson.GeoJsonPolygon)1 ArrayList (java.util.ArrayList)1