谷歌地图Android版API V2,如何从地图上删除折线? [英] Google Maps Android API v2, how to remove Polylines from the map?

查看:440
本文介绍了谷歌地图Android版API V2,如何从地图上删除折线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图删除previously增加折线,当位置已经改变重绘新的折线。我想这两个

this.routeToDestination.setPoints(pointsToDestination)和
    this.routeToDestination.remove()

但他们都没有工作。

我也跟着<一个href=\"http://stackoverflow.com/questions/13933411/how-to-draw-a-dynamic-line-route-with-google-maps-android-api-v2\">How绘制与谷歌地图Android版API V2 动态线(路线),但未能解决该问题。

  @覆盖
    公共无效onResume(){
        super.onResume();        routeToDestination = mMap.addPolyline(新的PolylineOptions()
                。新增(新经纬度(location.getLatitude(),location.getLongitude()),
                        新的经纬度(this.destinationLatitude,this.destinationLongitude))
                .WIDTH(1)
                。颜色(Color.DKGRAY)        );
    }   @覆盖
    公共无效onLocationChanged(地点){        清单&LT;&经纬度GT; pointsToDestination =新的ArrayList&LT;&经纬度GT;();
        pointsToDestination.add(新经纬度(location.getLatitude(),location.getLongitude()));
        pointsToDestination.add(新经纬度(destinationLatitude,destinationLongitude));        this.routeToDestination.setPoints(pointsToDestination);
    }}


解决方案

要删除您只需要使用remove()方法的API中所述的折线。

  //添加行地图
折线行= mMap.addPolyline(新的PolylineOptions()
            。新增(新经纬度(location.getLatitude(),location.getLongitude()),
                    新的经纬度(this.destinationLatitude,this.destinationLongitude))
            .WIDTH(1)
            。颜色(Color.DKGRAY)//删除从地图中的同一行
line.remove();

I am trying to remove previously added Polyline and redraw new Polyline when the location has been changed. I tried both

this.routeToDestination.setPoints(pointsToDestination) and this.routeToDestination.remove()

but neither of them worked.

I followed How to draw a dynamic line (route) with Google Maps Android API v2 but could not resolved the issue

    @Override
    public void onResume() {
        super.onResume();

        routeToDestination = mMap.addPolyline(new PolylineOptions()
                .add(new LatLng(location.getLatitude(), location.getLongitude()),
                        new LatLng(this.destinationLatitude, this.destinationLongitude))
                .width(1)
                .color(Color.DKGRAY)

        );
    }

   @Override
    public void onLocationChanged(Location location) {

        List<LatLng> pointsToDestination = new ArrayList<LatLng>();
        pointsToDestination.add(new LatLng(location.getLatitude(), location.getLongitude()));
        pointsToDestination.add(new LatLng(destinationLatitude, destinationLongitude));

        this.routeToDestination.setPoints(pointsToDestination);
    }

}

解决方案

To remove a polyline you should simply use remove() method as stated in the API.

//Add line to map
Polyline line = mMap.addPolyline(new PolylineOptions()
            .add(new LatLng(location.getLatitude(), location.getLongitude()),
                    new LatLng(this.destinationLatitude, this.destinationLongitude))
            .width(1)
            .color(Color.DKGRAY)

//Remove the same line from map
line.remove();

这篇关于谷歌地图Android版API V2,如何从地图上删除折线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆