我有这种方法:
public void crowdArea(){
for (int n=0; n<place.length; n++) {
Location locationFromDB2 = new Location("");
locationFromDB2.setLatitude(latt2[n]);
locationFromDB2.setLongitude(longg2[n]);
total = 0;
double c [][]=new double[100][2];
double p [][]=new double[100][2];
for (int n2 = 0; n2 < latt.length; n2++) {
Location locationFromDB3 = new Location("");
locationFromDB3.setLatitude(latt[n2]);
locationFromDB3.setLongitude(longg[n2]);
float dist = locationFromDB2.distanceTo(locationFromDB3);
if (dist < 500f) {
c [total][0]=latt[n2];
c [total][1]=longg[n2];
p [total][0]=prelatt[n2];
p [total][1]=prelongg[n2];
total++;
}
}
if (total >= 5) {
draw(latt2[n], longg2[n]);
state[n]="yes";
boolean b=bearing2(c,p);
Log.d("diriction is: ", b+"");
}
else{
state[n]="no";
// draw2(latt2[n], longg2[n]);
}
}
}
public void draw(double lat, double lonng){
Circle myCircle;
LatLng lt=new LatLng(lat, lonng);
CircleOptions circleOptions = new CircleOptions()
.center(lt) //set center
.radius(500) //set radius in meters
.fillColor(0x40ff0000) //default
.strokeColor(Color.RED)
.strokeWidth(5);
myCircle = map.addCircle(circleOptions);
}
在我的地图上画了一个圆圈。每15秒调用一次此方法,但它会在前一个圆上绘制一个圆,依此类推。我想要的是在添加新圈子之前删除以前的圈子。
这该怎么做?
您可以map.clear()
在绘制新圆之前先清除地图。
另外,如果您在地图上绘制了其他对象,但又不想删除它们,只需删除先前的Circle,就可以执行以下操作:
private Circle myCircle;
// ...
public void draw(double lat, double lonng){
LatLng lt=new LatLng(lat, lonng);
CircleOptions circleOptions = new CircleOptions()
.center(lt) //set center
.radius(500) //set radius in meters
.fillColor(0x40ff0000) //default
.strokeColor(Color.RED)
.strokeWidth(5);
if (myCircle != null) {
myCircle.remove();
}
myCircle = map.addCircle(circleOptions);
}
FOLLOWUP根据您的代码更新:
private List<Circle> circles = new ArrayList<>();
public void crowdArea(){
clearCircles();
for (int n=0; n<place.length; n++) {
Location locationFromDB2 = new Location("");
locationFromDB2.setLatitude(latt2[n]);
locationFromDB2.setLongitude(longg2[n]);
total = 0;
double c [][]=new double[100][2];
double p [][]=new double[100][2];
for (int n2 = 0; n2 < latt.length; n2++) {
Location locationFromDB3 = new Location("");
locationFromDB3.setLatitude(latt[n2]);
locationFromDB3.setLongitude(longg[n2]);
float dist = locationFromDB2.distanceTo(locationFromDB3);
if (dist < 500f) {
c [total][0]=latt[n2];
c [total][1]=longg[n2];
p [total][0]=prelatt[n2];
p [total][1]=prelongg[n2];
total++;
}
}
if (total >= 5) {
draw(latt2[n], longg2[n]);
state[n]="yes";
boolean b=bearing2(c,p);
Log.d("diriction is: ", b+"");
}
else{
state[n]="no";
// draw2(latt2[n], longg2[n]);
}
}
}
public void draw(double lat, double lonng){
LatLng lt=new LatLng(lat, lonng);
CircleOptions circleOptions = new CircleOptions()
.center(lt) //set center
.radius(500) //set radius in meters
.fillColor(0x40ff0000) //default
.strokeColor(Color.RED)
.strokeWidth(5);
circles.add(map.addCircle(circleOptions));
}
private void clearCircles() {
for (Circle circle : circles) {
circle.remove();
}
circles.clear();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句