Google Maps API v2 を約 1 か月使用しています。イシュートラッカーで報告された他のバグとは別に、次の奇妙なバグに遭遇しました。
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);
}