Increase radius on heat map for Maps API on Androi

2019-08-09 10:30发布

问题:

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.