我有这段代码,但是当我尝试刷新热力图点时,没有任何反应。我不知道是否需要其他东西,我已经查看了示例,但在我的情况下它不起作用。我正在使用碎片。
是否有其他方法可以刷新热力图层而无需重建地图对象?
是否有其他方法可以刷新热力图层而无需重建地图对象?
public class tab2 extends Fragment{
MapView mapView;
GoogleMap MygoogleMap;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view =inflater.inflate(R.layout.tab2, container, false);
mapView = (MapView) view.findViewById(R.id.mi_mapa);
mapView.onCreate(savedInstanceState);
MygoogleMap = mapView.getMap();
MygoogleMap.setMyLocationEnabled(true);
MapsInitializer.initialize(this.getActivity());
latitude = 18.916;
longitude = -99.236;
MygoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,
longitude), 3.5f));
return view;
}
public void setHotPoints(){
Handler_sqlite_mapa helper = new Handler_sqlite_mapa(this.miContexto);
helper.abrir(); //Abre la conexion a la BD
String resultado[][] = helper.getTop(99);
helper.cerrar();
int lecturasConfirmadas=0;
int columnas = (resultado.length);
int filas = (resultado[0].length);
Log.d("MiMapa:", "Columnas:" + columnas);
Log.d("MiMapa:", "Filas:" + filas);
if (mProvider == null) {
List<LatLng> list = new ArrayList<LatLng>();
String valores = "";
for(int i = 0; i < filas; i++) {
if(resultado[3][i]!=null){
double la = Double.parseDouble(resultado[1][i]);
double lo = Double.parseDouble(resultado[2][i]);
list.add(new LatLng(la,lo));
lecturasConfirmadas++;
}
}
if(lecturasConfirmadas>0){
MygoogleMap.clear();
mProvider = new HeatmapTileProvider.Builder()
.data(list)
.build();
mOverlay = MygoogleMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));
mOverlay.clearTileCache();
}
}
}
}
mOverlay.remove();
并创建一个新的图层,或者你可以使用HeatmapTileProvider.setData()
和clearTileCache()
来更改数据集。如果你还没有查看文档,请查看一下。希望这能帮到你。 - not_a_bot