Fix or remove part of google maps v2 polyline

I drew polylines for different points, as in this image. image1
CENTER VIEW: - (CIRCLE) Code for ** MARKER**:

viewIntermediateMarker = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.layout_intermediate_marker, null);

middlemarker = map.addMarker(new MarkerOptions()
                    .position(MIDDLE)
                    .snippet(String.valueOf(MIDDLE))
                    .icon(BitmapDescriptorFactory
                            .fromBitmap(SearchNearByCourseActivity
                                    .createDrawableFromView(mContext,
                                            viewIntermediateMarker))));

Polyline (White color):

poly_TToMid = map.addPolyline(new PolylineOptions()
                        .add(MIDDLE_MARKER, TEE_POINT).width(3)
                        .color(Color.WHITE));

Polyline (green color):

    poly_MidToFlage = map.addPolyline(new PolylineOptions()
                        .add(MIDDLE_MARKER, upperSquMidLat).width(3)
                        .color(Color.GREEN));

But what I want to do with my image 1 in picture 2, that is, I want to delete (crop) the polyline (green and white) inside the center of the circle, as shown in the figure below. image2

Please suggest some answers on how to do this in android Google map v2 API. Any help appreciated ...

+4
source share
1 answer

, . , .

. , / .

:

. :

List<LatLng> points = polyline.getPoints();

LatLng latLng = points.get(0);
// Get the starting point lat lng coordinates
Location startLoc = new Location("Test");
startLoc.setLatitude(latLng.latitude);
startLoc.setLongitude(latLng.longitude);

for (int i=1; i<points.size(); i++) {
    Location loc = new Location("Test");
    loc.setLatitude(points.get(i).latitude);
    loc.setLongitude(points.get(i).longitude);

    float distance = startLoc.distanceTo(loc);

    if (distance >= radiusInMeters) {
        polyline.setPoints(points.subList(i, points.size()));
        break;
    }
}

, , ( ), distanceTo , radiusInMeters . , ( ).

- (-) . , .

List<LatLng> points = polyline.getPoints();
final LatLng latLng = points.get(0);

mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
    @Override
    public void onMapLoaded() {
        mMap.snapshot(new GoogleMap.SnapshotReadyCallback() {
            @Override
            public void onSnapshotReady(Bitmap bitmap) {
                if (bitmap == null) {
                    Log.e(TAG, "Error! Snapshot couldn't be taken.");
                    return;
                }

                // Get the screen coordinates
                Point point = mMap.getProjection().toScreenLocation(latLng);
                if (point == null || point.x <= 0 || point.y <= 0) {
                    Log.e(TAG, "Error! Couldn't get the lat-lng coordinates.");
                    return;
                }

                int color = bitmap.getPixel(point.x, point.y);

                // Draw your marker using `color` as the background
            }
        });
    }
});

getPixels .

:

  • / , , , .
  • , - .
0

All Articles