title: (Android - Google Maps) Why polyline automatically making a closed figure
body: <p>I've been developing a map based app. In that I'm showing bus routes with the help of Polylines. Everything works fine as you can see in this image:</p>
  <p><a href="https://i.stack.imgur.com/tI1jX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tI1jX.png" alt="First start" /></a></p>
  <p>But when I restart the app or revisit map activity, the polyline automatically connects the last and very first points (co-ordinates),thus making a closed figure.</p>
  <p><a href="https://i.stack.imgur.com/NxVIe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NxVIe.png" alt="Revisit" /></a></p>
  <p>So is there any way by which I can stop the map from doing this?</p>
  <h3>Source code for map fragment</h3>
  <pre><code>public class MapFragment extends Fragment {
  
  GoogleMap gmaps;
  ArrayList&lt;LatLng&gt;coo = ProcessLatLng.getCoordinates(); //Getting co-ordinates into Array List
  
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      View v=inflater.inflate(R.layout.map_fragment, container, false);
      prepareMap();
      return v;
  }
  
  private void prepareMap() {
      int i;
      if(gmaps == null)
          gmaps = ((com.google.android.gms.maps.MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
      
      if(gmaps != null){
          PolylineOptions pop= new PolylineOptions();
          
          pop.width(5).color(Color.BLUE);
          
          for(i=0;i&lt;coo.size();i++){
              pop.add(coo.get(i));
          }
                  
          gmaps.addPolyline(pop);
          
          gmaps.addMarker(new MarkerOptions().position(coo.get(0)).title(&quot;Start&quot;));
          gmaps.addMarker(new MarkerOptions().position(coo.get(coo.size()-1)).title(&quot;End&quot;));
      
          gmaps.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.846785, 80.945591), 13));
      }
      
  }
  </code></pre>