需要删除最后的折线并创建当前的折线 [英] need to remove last polyline and create current polyline

查看:90
本文介绍了需要删除最后的折线并创建当前的折线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的谷歌地图与谷歌方向我使用类 http://www.akexorcist.com/2015/12/google-direction-library-for-android-en.html
某人为Google方向建立的。一切都很好,
和地图上显示的折线。但是当我需要点击另一个方向时,例如行走方向或驾驶方向,我会在地图上看到2条折线,而我只想看到当前的折线。



这里我创建多段线
并在开始时删除多段线,然后多段线完全不显示。
我不想那样。我希望当我点击其他按钮时,折线将被删除。
我尝试把polyline.remove();按钮单击其他但问题,如果,polyline.remove();在圆括号之外,polyline.remove();不要删除折线。我需要调用polyline.remove();当我点击其他按钮,但我卡住了。
这里是代码:

  switch(direction.getStatus()){
case RequestResult.OK :
Route route = direction.getRouteList()。get(0);

Leg leg = route.getLegList()。get(0);

ArrayList< LatLng> pointList = leg.getDirectionPoint();

列表< Step> stepList = direction.getRouteList()。get(0).getLegList()。get(0).getStepList();
ArrayList< PolylineOptions> polylineOptionList = DirectionConverter.createTransitPolyline(this,stepList,5,Color.RED,3,Color.BLUE); (PolylineOptions polylineOption:polylineOptionList)

polyline = mMap.addPolyline(polylineOption);
polyline.remove();

}

break;

2.当我点击步行按钮时,我希望过境折线将删除
只是一直在地图上只有一条折线。
我该怎么做?

  bWalking.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
if(locationGpsLatLng == null){
Toast.makeText(MapsActivity.this,需要GPS位置,``输入代码here`Toast.LENGTH_SHORT ).show(); {
return;
}
}
if(markerLocation == null){
Toast.makeText(MapsActivity.this,Type on标记浴室的目的地,Toast.LENGTH_SHORT).show();
} else {
sendRequestW alkingDirection();


}
};
private void sendRequestWalkingDirection(){
GoogleDirection.withServerKey(APIKEY)$ b $ .from(locationGpsLatLng)
.to(markerLocation)
.transportMode(TransportMode.WALKING)
.execute(new DirectionCallback(){
@Override $ b $ public void onDirectionSuccess(Direction direction,String rawBody){
Log.d(onDirectionSuccess,status:+ direction .getStatus());
requestOk(direction,rawBody);
mMap.addMarker(new MarkerOpt离子()。position(locationGpsLatLng).draggable(false).icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(locationGpsLatLng,15);
mMap.animateCamera(cameraUpdate);
}
@Override
public void onDirectionFailure(Throwable t){
return;
}
});
}
});


解决方案

您可以调用 mMap。清除(); 按钮点击后。
该方法将删除所有折线。



GoogleMap类文档
$ b 更新



您需要将多段线保存到某个列表中,然后在单击该按钮时将其删除。

 私人列表< Polyline>折线; 

将多段线添加到列表中

  polylines = new ArrayList<>(); (PolylineOptions polylineOption:polylineOptionList)

polyline = mMap.addPolyline(polylineOption);
polylines.add(polyline);
}

点击按钮后



< (折线折线:多段线){
polyline.remove(); pre>
}


i do google map with google direction i use class http://www.akexorcist.com/2015/12/google-direction-library-for-android-en.html that someone build for google direction. everything is work good, and the polyline show on the map. but when i need to click another direction like walking direction or drive direction i see 2 polyline on the map and i want to see only the current polyline.

here i create the polyline and remove the polyline in the start, then the polyline not show at all. i dont want that. i want when i click else button the polyline will remove. i try to put, polyline.remove(); on button click else but the problem that if, polyline.remove(); outside the parentheses, polyline.remove(); dont remove the polyline. i need to call polyline.remove(); when i click other button but i stuck. here is the code:

    switch (direction.getStatus()) {
        case RequestResult.OK:
            Route route = direction.getRouteList().get(0);

            Leg leg = route.getLegList().get(0);

            ArrayList<LatLng> pointList = leg.getDirectionPoint();

            List<Step> stepList = direction.getRouteList().get(0).getLegList().get(0).getStepList();
            ArrayList<PolylineOptions> polylineOptionList = DirectionConverter.createTransitPolyline(this, stepList, 5, Color.RED, 3, Color.BLUE);
            for (PolylineOptions polylineOption : polylineOptionList) {
                polyline = mMap.addPolyline(polylineOption);
                polyline.remove();

            }

                break;

2.when i click in walking button i want the transit polyline will remove that we have just all the time, only one polyline in the map. how i do that?

   bWalking.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            if (locationGpsLatLng == null) {
                                                Toast.makeText(MapsActivity.this, "Need GPS location", `enter code here`Toast.LENGTH_SHORT).show();{
                                                    return;
                                                }
                                            }
                                            if (markerLocation == null) {
                                                Toast.makeText(MapsActivity.this, "Type on marker bathroom for destination", Toast.LENGTH_SHORT).show();
                                            } else {
                                            sendRequestWalkingDirection();


                                        }
                                    };
                                    private void sendRequestWalkingDirection() {
                                        GoogleDirection.withServerKey(APIKEY)
                                                .from(locationGpsLatLng)
                                                .to(markerLocation)
                                                .transportMode(TransportMode.WALKING)
                                                .execute(new DirectionCallback() {
                                                    @Override
                                                    public void onDirectionSuccess(Direction direction, String rawBody) {
                                                        Log.d("onDirectionSuccess", "status: " + direction.getStatus());
                                                        requestOk(direction, rawBody);
                                                        mMap.addMarker(new MarkerOptions().position(locationGpsLatLng).draggable(false).icon(BitmapDescriptorFactory
                                                                .defaultMarker(BitmapDescriptorFactory.HUE_RED)));
                                                        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(locationGpsLatLng, 15);
                                                        mMap.animateCamera(cameraUpdate);
                                                    }
                                                    @Override
                                                    public void onDirectionFailure(Throwable t) {
                                                        return;
                                                    }
                                                });
                                    }
   });

解决方案

You can call mMap.clear(); after the button click. That method will remove all the polylines.

GoogleMap class documentation

UPDATE

You need to save the polylines to some list and then remove them when the button is clicked

private List<Polyline> polylines;

Add the polylines to the list

polylines = new ArrayList<>();
for (PolylineOptions polylineOption : polylineOptionList) {
    polyline = mMap.addPolyline(polylineOption);
    polylines.add(polyline);
}

After button click

for (Polyline polyline : polylines) {
    polyline.remove();
}

这篇关于需要删除最后的折线并创建当前的折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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