0

我已经使用谷歌地图 api v2 大约一个月了。除了问题跟踪器中报告的其他错误之外,我还遇到了以下奇怪的错误。

java.lang.IllegalStateException:相机在取消期间移动,这发生在我用于 animateCamera 方法的 CancelableCallback 中。异常追溯到用户触摸事件。我相信发生这种情况是因为用户在调用 onFinish/onCancel 时正在与地图进行交互,现在这种情况并不经常发生,但它很烦人。

反正有这个问题吗?我将不胜感激您能提供的任何帮助。

这是一个完整的代码:

public void moveMapToSearchMarker(
        final T fmMarker,
        final FriendlyMapGoogleMapMarkerClickListener fmMarkerClickListener,
        float zoomLevel) {
    CameraUpdate camUpdate = CameraUpdateFactory.newLatLngZoom(fmMarker
            .getMarker().getPosition(), zoomLevel);
    getGoogleMap().animateCamera(camUpdate, new CancelableCallback() {
        @Override
        public void onFinish() {
            setMarkerOnSearchComplete(fmMarker, fmMarkerClickListener);

        }

        @Override
        public void onCancel() {
            setMarkerOnSearchComplete(fmMarker, fmMarkerClickListener);
        }
    });
}

private void setMarkerOnSearchComplete(T fmMarker,
        FriendlyMapGoogleMapMarkerClickListener fmMarkerClickListener) {
    if (!fmMarker.getMarker().isVisible())
        fmMarker.getMarker().setVisible(true);
    for (T lstFmMarker : this)
        lstFmMarker.setSearched(false);
    fmMarker.setSearched(true);
    createOrUpdateSearchMarker(fmMarker.getMarker().getPosition());
    fmMarkerClickListener.onFriendlyMapMarkerClick(fmMarker, this, true);
}
public void createOrUpdateSearchMarker(LatLng searchMarkerPos) {


    if (searchRadiusCircle == null) {
        CircleOptions cOpts = new CircleOptions();
        int strokeColor = getSearchRadiusColor() + 0xEE000000;
        cOpts.center(searchMarkerPos).fillColor(getSearchRadiusColor())
                .strokeColor(strokeColor).radius(12).strokeWidth(2F);
        searchRadiusCircle = getGoogleMap().addCircle(cOpts);
    } else {
        searchRadiusCircle.setVisible(true);
        searchRadiusCircle.setCenter(searchMarkerPos);
    }

}

public <T extends FriendlyMapMarker> boolean onFriendlyMapMarkerClick(
        T fmMarker, FriendlyMapMarkerList fmMarkerList,
        boolean isOnCancelableCallback) {
    FriendlyMapMarkerAndList fmMapMarkerAndList = new FriendlyMapMarkerAndList<FriendlyMapMarker, FriendlyMapMarkerList>();
    fmMapMarkerAndList.fmMarker = fmMarker;
    fmMapMarkerAndList.fmMarkerList = fmMarkerList;
    return handleMarkerClick(fmMapMarkerAndList, isOnCancelableCallback);
}
private boolean handleMarkerClick(
        FriendlyMapMarkerAndList fmMapMarkerAndList,
        boolean isOnCancelableCallback) {
    if (fmMapMarkerAndList == null)
        return false;
    final FriendlyMapMarker fmMarker = fmMapMarkerAndList.fmMarker;
    Marker marker = fmMarker.getMarker();
    final FriendlyMapMarkerList fmMarkerList = fmMapMarkerAndList.fmMarkerList;
    if (fmMarker != null) {

        if (fmMarker.getClass().equals(FriendlyMapPlaceMarker.class)) {
            balloonActions.setCurrentFmMarker(fmMarker);
            balloonActions.setPlaceLikeButtonVisibility();

            CancelableCallback onCameraCompleteMove = new CancelableCallback() {
                @Override
                public void onFinish() {
                    openActionBalloon(fmMarker, fmMarkerList);
                }

                @Override
                public void onCancel() {
                    openActionBalloon(fmMarker, fmMarkerList);

                }
            };
            LatLng camPos = Utils.getRoundedLatLng(fmMarkerList
                    .getGoogleMap().getCameraPosition().target, 1e5);
            LatLng markerPos = Utils.getRoundedLatLng(marker.getPosition(),
                    1e5);
            if (!Utils.latLngEqualsByCoords(camPos, markerPos)
                    && !isOnCancelableCallback)
                fmMarkerList.getGoogleMap()
                        .animateCamera(
                                CameraUpdateFactory.newLatLng(fmMarker
                                        .getLatLng()), 350,
                                onCameraCompleteMove);
            else
                onCameraCompleteMove.onFinish();
            fmMarker.getMarker().showInfoWindow();
            LoadAsyncBalloonExtendedStatisticsResult loadAsyncBalloonStatisticsResult = new LoadAsyncBalloonExtendedStatisticsResult(
                    activity, marker,
                    (FriendlyMapPlaceMarkerList) fmMarkerList);
            loadAsyncBalloonStatisticsResult
                    .execute(((FriendlyMapPlaceMarker) fmMarker)
                            .getKnownLocationID());
            return true;
        }
        if (fmMarker.getClass().equals(FriendlyMapDiscussionMarker.class)) {
            balloonActionsDiscussion.setCurrentFmMarker(fmMarker);
            final FriendlyMapDiscussionMarker fmdMarker = (FriendlyMapDiscussionMarker) fmMarker;
            LatLng camPos = Utils.getRoundedLatLng(fmMarkerList
                    .getGoogleMap().getCameraPosition().target, 1e5);
            LatLng markerPos = Utils.getRoundedLatLng(fmdMarker.getMarker()
                    .getPosition(), 1e5);
            if (!Utils.latLngEqualsByCoords(camPos, markerPos)
                    && !isOnCancelableCallback) {
                CameraUpdate camUpdate = CameraUpdateFactory
                        .newLatLng(fmdMarker.getMarker().getPosition());
                fmMarkerList.getGoogleMap().animateCamera(camUpdate, 350,
                        new CancelableCallback() {
                            @Override
                            public void onFinish() {
                                openWindowInfoActionBalloon(fmMarkerList,
                                        fmdMarker);
                            }

                            @Override
                            public void onCancel() {
                                openWindowInfoActionBalloon(fmMarkerList,
                                        fmdMarker);

                            }
                        });
            } else {
                openWindowInfoActionBalloon(fmMarkerList, fmdMarker);
            }

            return true;
        }
        if (fmMarker.getClass().equals(FriendlyMapThoughtMarker.class)) {
            balloonActionThought.setCurrentFmMarker(fmMarker);
            balloonActionThought.setDeleteButtonVisiblity();
            final FriendlyMapThoughtMarker fmtMarker = (FriendlyMapThoughtMarker) fmMarker;
            LatLng camPos = Utils.getRoundedLatLng(fmMarkerList
                    .getGoogleMap().getCameraPosition().target, 1e5);
            LatLng markerPos = Utils.getRoundedLatLng(fmtMarker.getMarker()
                    .getPosition(), 1e5);
            if (!Utils.latLngEqualsByCoords(camPos, markerPos)
                    && !isOnCancelableCallback) {
                CameraUpdate camUpdate = CameraUpdateFactory
                        .newLatLng(fmtMarker.getMarker().getPosition());
                fmMarkerList.getGoogleMap().animateCamera(camUpdate, 350,
                        new CancelableCallback() {
                            @Override
                            public void onFinish() {
                                openWindowInfoActionBalloon(fmMarkerList,
                                        fmtMarker);
                            }

                            @Override
                            public void onCancel() {

                                openWindowInfoActionBalloon(fmMarkerList,
                                        fmtMarker);
                            }
                        });
            } else {
                openWindowInfoActionBalloon(fmMarkerList, fmtMarker);
            }
            return true;
        }
    }
    return false;
}
private void openWindowInfoActionBalloon(
        FriendlyMapMarkerList fmMarkerList, FriendlyMapMarker fmMarker) {
    Marker m = fmMarker.getMarker();
    m.showInfoWindow();
    openActionBalloon(fmMarker, fmMarkerList);
}
private void openActionBalloon(FriendlyMapMarker marker,
        FriendlyMapMarkerList fmMarkerList) {

    Projection proj = fmMarkerList.getGoogleMap().getProjection();
    Point markerScreenPoint = proj.toScreenLocation(marker.getMarker()
            .getPosition());

    if (marker.getClass().equals(FriendlyMapPlaceMarker.class)) {
        balloonActionsDiscussion.setVisibility(View.INVISIBLE);
        balloonActionThought.setVisibility(View.INVISIBLE);
        setBalloonDimension(balloonActions, markerScreenPoint);

    } else if (marker.getClass().equals(FriendlyMapDiscussionMarker.class)) {

        balloonActions.setVisibility(View.INVISIBLE);
        balloonActionThought.setVisibility(View.INVISIBLE);
        setBalloonDimension(balloonActionsDiscussion, markerScreenPoint);

    } else if (marker.getClass().equals(FriendlyMapThoughtMarker.class)) {
        balloonActionsDiscussion.setVisibility(View.INVISIBLE);
        balloonActions.setVisibility(View.INVISIBLE);
        setBalloonDimension(balloonActionThought, markerScreenPoint);
    }

}
private void setBalloonDimension(View ballonActionView,
        Point markerScreenPoint) {
    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) ballonActionView
            .getLayoutParams();
    int marginX = markerScreenPoint.x - (ballonActionView.getWidth() / 2);
    int marginY = markerScreenPoint.y;
    params.setMargins(marginX, marginY, -marginX, -marginY);
    params.gravity = Gravity.NO_GRAVITY;
    ballonActionView.setLayoutParams(params);
    ballonActionView.setVisibility(View.VISIBLE);
}
4

1 回答 1

0

我建议将带有堆栈跟踪的错误发布到跟踪器。

at com.google.android.gms.maps.GoogleMap.animateCamera(Unknown Source)
at com.saipex.friendly_map.map_view_related_v2.FriendlyMapGoogleMapMarkerClickListener.handleMarkerClick(FriendlyMapGoogleMapMarkerClickListener.java:259)
at com.saipex.friendly_map.map_view_related_v2.FriendlyMapGoogleMapMarkerClickListener.onFriendlyMapMarkerClick(FriendlyMapGoogleMapMarkerClickListener.java:133)
at com.saipex.friendly_map.map_view_related_v2.model.FriendlyMapMarkerList.setMarkerOnSearchComplete(FriendlyMapMarkerList.java:163)
at com.saipex.friendly_map.map_view_related_v2.model.FriendlyMapMarkerList.access$0(FriendlyMapMarkerList.java:155)
at com.saipex.friendly_map.map_view_related_v2.model.FriendlyMapMarkerList$1.onCancel(FriendlyMapMarkerList.java:181)

看起来你正在尝试一些被禁止的东西:在 onCancel 中为相机设置动画。该代码将向我们展示更多信息。

于 2013-04-04T21:03:58.363 回答