I need to show location A and the location B by pulse animation. I am able to achieve that using the below code. But the problem I am facing is the GroundOverlay changes its
So let's say you want the overlay circle radius to be a fixed dimension (relative to screen pixels) for example 1/10th of the screen width (at the current zoom).
// compute width of visible region
// get lat-lng of left and right points
LatLng left = googleMap.getProjection().getVisibleRegion().farLeft;
LatLng right = googleMap.getProjection().getVisibleRegion().farRight;
// compute distance between points
float[] results = new float[1];
Location.distanceBetween(left.latitude, left.longitude,right.latitude,right.longitude, results);
// scale to desired relative radius size
float scaledRadius = results[0] * 0.10F;
// and use that for radius - taken from OP code and use 'scaledRadius'
final GroundOverlay circle = googleMap.addGroundOverlay(new GroundOverlayOptions()
.position(latLng, scaledRadius).image(BitmapDescriptorFactory.fromBitmap(bitmap)));
This example uses width as the scaling axis but you could just as well use height or diagonal (by using different points of the projection).
The use of 'far' can be replaced with 'near' - it is used to account for tilt so you'll have to experiment.
So now your resource value is a scaling factor and not an absolute radius value - so for this example you would set the resource value to 0.10F and use that where's it hard-coded above.
If you want the pulse (and overlay) to work after/during zoom then you'll need to update the width of the overlay circle (circle.setWidth(scaledRadius)) using the 'onCameraIdle' event - using the same computation as above for scaledRadius, such as:
public void onCameraIdle() {
if (circle != null) {
// compute scaled radius as in above code...
// The 1-argument version is specifically width
circle.setDimensions(scaledRadius);
}
}