Increase radius on heat map for Maps API on Android

蓝咒 提交于 2019-12-11 10:09:00

问题


I've created an heat map on Google Maps API for Android. The problem is when I increase zoom, the heat map "looses" radius and the look is not that good.

There`s a way to increase radius above 50 (Probably the maximum)? :/


回答1:


From the documentation:

Radius: The size of the Gaussian blur applied to the heatmap, expressed in pixels. The default is 20. Must be between 10 and 50. Use the Builder's radius() to set the value when creating the heatmap, or change the value later with setRadius().

So, if you use the radius(int val) function from the HeatmapTileProvider.Builder you will receive an IllegalArgumentException("Radius not within bounds.") exception if the radius is not between 10 an 50.

Taking a look at the GitHub repository you can see that the radius(int val) function checks if the parameter is between MIN_RADIUS and MAX_RADIUS.

Anyway there is a setRadius(int radius) function on the HeatmapTileProvider class that you can use (take a look at he implementation in the GitHub repository).

So, as the setRadius(int radius) function does not check the parameter, you can change the radius of the HeatmapTileProvider after calling build() as follows:

HeatmapTileProvider mProvider = new HeatmapTileProvider.Builder()
        .data(list)
        .build();
mProvider.setRadius(100);

Using the police stations example, and setting the radius to 50:

And setting the radius to 100:

You may want to dynamically change the radius of the HeatMap based on the zoom level.

NOTE: Take into account that, as stated in the Javadoc for the setRadius function:

User should clear overlay's tile cache (using clearTileCache()) after calling this.



来源:https://stackoverflow.com/questions/35257612/increase-radius-on-heat-map-for-maps-api-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!