我正在使用android API for heatmap 。我已导入依赖项并在 Activity 结束时添加了热图代码。
List<String> temp = Arrays.asList(coordinates.get(i).split(";"));
LatLng coor = new LatLng(Double.parseDouble(temp.get(1)), Double.parseDouble(temp.get(2)));
// Create a heat map tile provider, passing it the latlngs
WeightedLatLng data = new WeightedLatLng(coor, Double.parseDouble(temp.get(0)) );
mProvider = new HeatmapTileProvider.Builder()
//.weightedData(data) //doesn't work
.data(coor) //doesn't work either
.build();
}
我在weightedData行中收到以下错误:
WeightedData(java.util.Collection<com.google.maps.android.heatmaps.WeightedLatLng>) in Builder cannot be applies (com.google.maps.android.heatmaps.WeightedLatLng)
我尝试添加 Actor ,但这会使应用程序崩溃。我已经在谷歌上搜索了很长时间并尝试了各种各样的事情。有什么想法吗?
最佳答案
构建器weightedData和数据方法将集合作为参数:
weightedData(Collection<WeightedLatLng> val)
尝试将所有数据添加到 ArrayList 中,然后将其传递给构建器。
WeightedLatLng data = new WeightedLatLng(coor, Double.parseDouble(temp.get(0)) );
ArrayList<WeightedLatLng> weightedLatLngs = new ArrayList<>();
weightedLatLngs.add(data);
mProvider = new HeatmapTileProvider.Builder().weightedData(weightedLatLngs).build();
理想情况下,您的热图应包含许多加权纬度,因此循环遍历您的坐标并将它们全部添加到数组列表中。
关于android - WeightedLatLng 和集合<WeightedLatLng>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32740231/