issue with removing polyline google map v2 android

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-14 07:16:08

问题


I am adding a polyline option simply as in google developer's website.

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)); // Closes the polyline.

// Get back the mutable Polyline
Polyline polyline = myMap.addPolyline(rectOptions);

I want to remove it. but there is no rectOptions.remove() I did update google play services from my sdk as mentioned in Google Maps Android API v2, how to remove Polylines from the map? But still I dont have it. Should I do something more after just updating it from SDK manager? I really need to remove it and not make it invisible to save memory cause I will show a path of lots of points and for many times.


回答1:


To remove the Polyline, use polyline.remove();




回答2:


You shouldn't use PolylineOptions to remove it.

Use PolyLine like this

polyline.remove();

Documentation

public void remove ()

Removes this polyline from the map. After a polyline has been removed, the behavior of all its methods is undefined.



来源:https://stackoverflow.com/questions/15155822/issue-with-removing-polyline-google-map-v2-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!