我想要可见的标记(例如默认的Google地图)放置图标可见性。 在默认地图中,图标的可见性根据地图相机的缩放级别和相机位置而更改。更改相机位置时,其他人可以看到该特定区域的图标。现在,我从SQLite数据库中获取了可见区域的数据,但是我从地图上删除了所有标记,然后再次添加。因此,在此过程中,标记会闪烁(删除并再次添加)。
我的代码:
@Override
public void onCameraIdle() {
Log.i("TAG", "onCameraIdle");
if (cameraMoveReason == REASON_GESTURE) {
LatLngBounds bounds = mGoogleMap.getProjection().getVisibleRegion().latLngBounds;
double minLat;
double maxLat;
double minLng;
double maxLng;
if (bounds.northeast.latitude > bounds.southwest.latitude) {
minLat = bounds.southwest.latitude;
maxLat = bounds.northeast.latitude;
} else {
minLat = bounds.northeast.latitude;
maxLat = bounds.southwest.latitude;
}
if (bounds.northeast.longitude > bounds.southwest.longitude) {
minLng = bounds.southwest.longitude;
maxLng = bounds.northeast.longitude;
} else {
minLng = bounds.northeast.longitude;
maxLng = bounds.southwest.longitude;
}
LocationDAO locationDAO = new LocationDAO(getActivity());
//Fetching data from SQLite database with latlng bounds
ArrayList<LocationDTO> locationDTOArrayList = locationDAO.getLocations(minLat, maxLat, minLng, maxLng);
googleMap.clear();
for (LocationDTO locationDTO : locationDTOArrayList) {
LatLng latLng = new LatLng(locationDTO.getLatitude(), locationDTO.getLongitude());
Bitmap sourceBitmap = BitmapFactory.decodeResource(activity.getResources(),
R.drawable.ic_location_white);
Bitmap bitmapIcon = changeBitmapColor(sourceBitmap, Color.parseColor(locationDTO.getColor()));
Marker marker = googleMap.addMarker(new MarkerOptions().position(latLng)
.icon(BitmapDescriptorFactory.fromBitmap(bitmapIcon)));
marker.setSnippet(String.valueOf(locationDTOArrayList.indexOf(locationDTO)));
marker.setTag(locationDTOArrayList.indexOf(locationDTO));
}
cameraMoveReason = -1;
}
}
@Override
public void onCameraMoveCanceled() {
Log.i("TAG", "onCameraMoveCanceled");
}
@Override
public void onCameraMoveStarted(int i) {
cameraMoveReason = i;
Log.i("TAG", "onCameraMoveStarted : " + i);
}
请提出一些建议,以实现流畅的图标可见性。