how to Remove PloylineOptions from google map - android

I draw ploy line by polylineOptions.addAll() . but i can't remove it from map.how to remove it?
PolylineOptions lineOptions = null;
lineOptions = new PolylineOptions();
lineOptions.addAll(points);
lineOptions.width(5);
lineOptions.color(Color.RED);

You just create object Polyline and just remove it, i think it will be working
PolylineOptions lineOptions = null;
lineOptions = new PolylineOptions();
lineOptions.addAll(points);
lineOptions.width(5);
lineOptions.color(Color.RED);
Polyline polyline = mGoogleMap.addPolyline(lineOptions);
polyline.remove();
or clear google map

Related

Bring markers above polyline with deprecated markers

How to bring all the markers above polyline. I'm using deprecated 'Marker' and 'LineManager' to draw marker and polyline.
I think with Layers its possible, but its hard for me to switch now, is there any with 'Marker'?
This is how i add marker and polyline
LatLng latLng = new LatLng(mLatLngList.get(i).getLatituede(), mLatLngList.get(i).getLongitude());
MarkerOptions markerOptions = new MarkerOptions().position(latLng).icon(icon).setTitle(cabList.get(i).getCabId());
Marker marker = mMapboxMap.addMarker(markerOptions);
mMapboxMap.setStyle(new Style.Builder().fromUrl(getString(R.string.mapbox_style_url_light)), style -> {
mLineManager = new LineManager(mMapView, mapboxMap, style);
LineOptions lineOptions = new LineOptions()
.withLatLngs(points)
.withLineJoin(Property.LINE_JOIN_ROUND)
.withLineColor(ColorUtils.colorToRgbaString(getResources().getColor(R.color.colorPrimary)))
.withLineWidth(4.0f);
mMapBoxLines = mLineManager.create(lineOptions);
});
I even tried manually removing line layer and adding below symbol layer, but it didn't work.
SymbolLayer symbolLayer = (SymbolLayer) mMapboxMap.getStyle().getLayer("mapbox-android-symbol-layer");
LineLayer lineLayer = (LineLayer) mMapboxMap.getStyle().getLayer("mapbox-android-line-layer");
mMapboxMap.getStyle().removeLayer(lineLayer);
mMapboxMap.getStyle().addLayerBelow(lineLayer, symbolLayer.getSourceId());
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.0.0'
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:4.3.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.4.0'

Dynamically draw a single polyline to current location

In my android app, I want to create a single path/polyline from a specific location(far end) to my current location while moving. I could draw the polyline on map with now issue while when I moves to a new location another polyline is been drown on the map, so my map output is full of polylines whichh I don't need, I want only one polyline to be visible to my current location.
PolylineOptions polylineOptions = new PolylineOptions().add(currentPosition).add(farEndPosition).width(10).color(Color.GREEN);
Polyline polyline = googleMap.addPolyline(polylineOptions);
Remove old Line before adding new one.
Polyline polyline ;
public void addUpdatePolyLine()
{
PolylineOptions polylineOptions = new PolylineOptions().add(currentPosition).add(farEndPosition).width(10).color(Color.GREEN);
if(polyline !=null)
{
polyline.remove();
}
polyline = googleMap.addPolyline(polylineOptions);
}

google maps android studio does not show my polyline

I don't know why this polyline won't show, I already put the google maps api and enabled the directions api as well
PolylineOptions rectOptions = new PolylineOptions();
rectOptions.add(new LatLng(24.009115, -104.699933));
rectOptions.add(new LatLng(24.009115, -104.699933));
rectOptions.width(5);
rectOptions.color(Color.RED);
Polyline polyline = mMap.addPolyline(rectOptions);
Add(), width() and color() all return a PolylineOptions with the new settings added.
PolylineOptions rectOptions = new PolylineOptions();
rectOptions =rectOptions.add(new LatLng(24.009115, -104.699933));
rectOptions =rectOptions.add(new LatLng(24.009115, -104.699933));
rectOptions =rectOptions.width(5);
rectOptions =rectOptions.color(Color.RED);
Polyline polyline = mMap.addPolyline(rectOptions);
or
PolylineOptions rectOptions = new PolylineOptions()
.add(new LatLng(24.009115,-104.699933),
new latlang(24.009115,-104.699933))
.width(5)
.color(Color.red);
Polyline polyline = mMap.addPolyline(rectOptions);
Source:https://developers.google.com/android/reference/com/google/android/gms/maps/model/PolylineOptions

Remove a line from PolyLine map in Google Map android V2?

I have searched in google and find this answer where i can remove all polyLine of a Map.
But I want to remove only a particular line from the poly Line. For Example I want to remove the line from 2nd to 3rd LatLng in the given code. I want to change color of a particular line of a polyLine or make it transparent. And I also want to add a clickListener to PolyLine
PolylineOptions rectOptions = new PolylineOptions()
.add(new LatLng(37.35, -122.0))
.add(new LatLng(37.45, -122.0)) // North of the previous point, but at the same longitude
.add(new LatLng(37.45, -122.2)) // Same latitude, and 30km to the west
.add(new LatLng(37.35, -122.2)) // Same longitude, and 16km to the south
.add(new LatLng(37.35, -122.0)).width(5).color(Color.RED);; // Closes the polyline.
Polyline polyline = myMap.addPolyline(rectOptions);
Main goal is to remove/make it transparent a particular line of a PolyLine on click or tap.
PolylineOptions line= new PolylineOptions().add(HAMBURG,// these are latlong
KIEL,
KIEL2,
KIEL3
new LatLng(40.748963847316034,
-73.96807193756104)
)
.width(5).color(Color.RED);
Polyline polyline= googleMap.addPolyline(line);
And i want to remov line between KIEL1 and KIEL2
You'll have to manually remove points from the polyline.
EDIT:
Step by step:
Create a List of polylines:
List<Polyline> mPolylines = new ArrayList<Polyline>();
Add PolylineOptions to the map:
Polyline polyline1 = myMap.addPolyline(rectOptions1);
Polyline polyline2 = myMap.addPolyline(rectOptions2);
Polyline polyline3 = myMap.addPolyline(rectOptions3);
Then save the added polylines to your array
mPolylines.add(polyline1);
mPolylines.add(polyline2);
mPolylines.add(polyline3);
Now at any time you can trim the polyline like so:
// Get polyline1
List<LatLng> points = mPolylines.get(0).getPoints();
// Set the bounds of points to remove (inclusive)
int startPoint = 1, endPoint = 2; // will remove kiel1 and kiel2
// Remove the points
for (int i=startPoint; i<=endPoint; i++) {
points.remove(i);
}
// Added this line as getPoints returns a copy
mPolylines.get(0).setPoints(points);
Now in theory this should work fine. I found that the points don't actually change after setPoints.
I even tried:
Polyline polyline = mPolylines.get(0);
// Get copy of the points
List<LatLng> points = polyline.getPoints();
mPolylines.get(0).remove();
mPolylines.remove(0);
for (int i=3000; i<7000; i++) {
points.remove(i);
}
// Create a PolylineOptions object with the new points
PolylineOptions polylineOptions = new PolylineOptions().addAll(points);
mPolylines.add(0, mMap.addPolyline(polylineOptions));
And to my surprise a new Polyline was added (I can tell by the changed stroke width and color), but it still used the old points, even though points.size() returned the correct (trimmed) count.
I'm not sure why this is so, perhaps some error in my code. You can try these methods yourself and see if you are any luckier.

Adding text to polyline google map

How to add text to multiple point on polyline for different coordinates.The polyline code is as follows:
PolylineOptions po = new PolylineOptions();
for (HashMap<String, String> point : coords) {
LatLng latlng = new LatLng(Double.parseDouble(map
.get("lat")), Double.parseDouble(map.get("long")));
po.add(latlng);
//po.add(new LatLng(27.3200,88.9711));
po.width(5);
po.color(0xFFFFFF00);

Categories

Resources