如何刷新 Google Maps Android API 实用程序库中热图图层的点?

Ben*_*min 5 android google-maps android-fragments

我有这段代码,但是当我尝试刷新热图点时,没有任何反应。我不知道我是否需要其他东西,我看过一些例子,但就我而言它不起作用。我正在使用碎片。

是否有其他方法可以刷新热图图层而不重建地图对象?

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();
        }

    }

}

}
Run Code Online (Sandbox Code Playgroud)

Sug*_*gre 2

不确定是否有更好的方法,我使用删除并重新创建来强制更新热图:

    private void removeHeatMap() {
        mOverlay.remove();
    }

    private void addHeatMap() {

        mProvider = new HeatmapTileProvider.Builder()
                .weightedData(samples)
                .build();
        mOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));
    }
Run Code Online (Sandbox Code Playgroud)

我注意到的一件事是,如果我没有使用叠加层重新创建 HeatmapTileProvider 实例,则热图将无法正确更新。