polyline.remove()&& marker.remove()不会删除Andorid

时间:2019-09-03 17:20:07

标签: java android-studio dictionary google-maps-markers polyline

可能的答案我应该在异步任务中实现OnMapReadyCallback吗?它会从异步中添加折线,但不会删除

如果我从asyncTask中删除相同的对象,则可以使用,但是如果删除了,则不再添加

它不为null,它与上一个任务中添加的对象相同,但请勿将其从地图中删除 也许我不知道某种碎片交易的问题:( 这是日志

删除之前 devicePositionMarker com.google.android.gms.maps.model.Marker@be8c250 去掉 devicePositionMarker com.google.android.gms.maps.model.Marker@be8c250 加 devicePositionMarker com.google.android.gms.maps.model.Marker@ab741fe

这是对象

@Getter
private Marker devicePositionMarker;

对于

private static class DrawOnMap extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
activity.runOnUiThread(new Runnable() {
                    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
                    @Override
                    public void run() {                 
           if (devicePositionMarker != null) {
                                Log.i("asyncMap", "Before remove devicePositionMarker "+devicePositionMarker);;
                                devicePositionMarker.remove();
                                Log.i("asyncMap", "remove devicePositionMarker "+devicePositionMarker);;
                                devicePositionMarker = mMap.addMarker(new MarkerOptions()
                                        .position(latLng)
                                        .visible(false)
                                );
                                devicePositionMarker.setIcon(BitmapDescriptorFactory.fromBitmap(
                                        iconFactory.makeIcon("Tutaj jesteś.")

                                ));
                                devicePositionMarker.setVisible(true);
                                Log.i("asyncMap", "add devicePositionMarker "+devicePositionMarker);
                                devicePositionMarker.remove();
                                Log.i("asyncMap", "Before remove devicePositionMarker "+devicePositionMarker);;
                            }
                    }
                });

            }
            return null;
        }

折线的相同问题

@Getter
private Polyline dottedLine;

与Ui线程中的doInBackground相同

                                LatLng DeviceLocation = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
                                if (dottedLine != null) {
                                    dottedLine.remove();
                                    Log.i("asyncMap", "remove dottedLine "+dottedLine);
                                    dottedLine = mMap.addPolyline(new PolylineOptions()
                                            .clickable(true)
                                            .pattern(PATTERN_POLYGON_ALPHA)
                                            .add(DeviceLocation
                                                    , pointsOfLatLng.get(0)
                                            ));
                                    dottedLine.setColor(Color.BLUE);
                                    Log.i("asyncMap", "add dottedLine "+dottedLine);
    ```


0 个答案:

没有答案