Coder Social home page Coder Social logo

Comments (3)

blackisthesoul avatar blackisthesoul commented on September 27, 2024 2

Just wanna share what I have done

` 
//put List on declaration
 List<Polyline> polylines = new ArrayList<Polyline>();

@Override
    public void onDirectionSuccess(Direction direction, String rawBody) {
        if (direction.isOK()) {
            for (int i = 0; i < direction.getRouteList().size(); i++) {
                Route route = direction.getRouteList().get(i);
                mMap.addMarker(new MarkerOptions().position(origin));
                mMap.addMarker(new MarkerOptions().position(destination));

                ArrayList<LatLng> directionPositionList = route.getLegList().get(0).getDirectionPoint();
                polylines.add(mMap.addPolyline(DirectionConverter.createPolyline(this, directionPositionList, 5, Color.RED)));

            }

            setCameraWithCoordinationBounds(direction.getRouteList().get(0));
            
            //btnRequestDirection.setVisibility(View.GONE);
        } else {
            //Snackbar.make(btnRequestDirection, direction.getStatus(), Snackbar.LENGTH_SHORT).show();
        }
    }`

And then when I want to remove polylines, I create a button to clear all my polylines

public void Clear(View view){ for(Polyline line : polylines) { line.remove(); } polylines.clear(); }

I hope it helps

from googledirectionlibrary.

starr0stealer avatar starr0stealer commented on September 27, 2024 1

@eeffoc

When you call googleMap.addPolyline() it returns the instance reference. Assign it to a variable, and then you can use the methods within the Polyline class. With the reference you can call Polyline.remove().

Google Docs: Polyline.remove

private Polyline directionsPath;

directionsPath = googleMap.addPolyline();

directionsPath.remove();

from googledirectionlibrary.

eeffoc avatar eeffoc commented on September 27, 2024

Thank you @starr0stealer wasn't aware that an instance is returned!

from googledirectionlibrary.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.