I found a solution for the Google Map API v2 from several answers:
https: //stackoverflow.com/questions/794954/...
So, you need to execute the Activity from the GoogleMap.OnCameraChangeListener interface
private static final int REQUEST_CODE_GOOGLE_PLAY_SERVECES_ERROR = -1;
private static final double EARTH_RADIOUS = 3958.75; // Earth radius;
private static final int METER_CONVERSION = 1609;
private GoogleMap mGoogleMap;
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_layout);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable (mContext);
if (status! = ConnectionResult.SUCCESS)
{
Dialog dialog = GooglePlayServicesUtil.getErrorDialog (status, activity,
REQUEST_CODE_GOOGLE_PLAY_SERVECES_ERROR);
dialog.show ();
mGoogleMap = null;
}
else
{
mGoogleMap = ((SupportMapFragment) getFragmentManager (). findFragmentById (
R.id.fragment_shops_layout_maps_fragment)). GetMap ();
mGoogleMap.setOnCameraChangeListener (this);
}
}
A listener that works when scaling a map. Define as LatLng the positions of the lower left, lower right, upper left, and upper right edges of the map that are displayed on the screen. For the most part of the screen and two points, we can get the radius from the center of the map.
@Override
public void onCameraChange (CameraPosition cameraPosition)
{
// Listener of zooming;
float zoomLevel = cameraPosition.zoom;
VisibleRegion visibleRegion = mGoogleMap.getProjection (). GetVisibleRegion ();
LatLng nearLeft = visibleRegion.nearLeft;
LatLng nearRight = visibleRegion.nearRight;
LatLng farLeft = visibleRegion.farLeft;
LatLng farRight = visibleRegion.farRight;
double dist_w = distanceFrom (nearLeft.latitude, nearLeft.longitude, nearRight.latitude, nearRight.longitude);
double dist_h = distanceFrom (farLeft.latitude, farLeft.longitude, farRight.latitude, farRight.longitude);
Log.d ("DISTANCE:", "DISTANCE WIDTH:" + dist_w + "DISTANCE HEIGHT:" + dist_h);
}
The return distance between 2 points, stored as 2 pairs in meters;
public double distanceFrom (double lat1, double lng1, double lat2, double lng2)
{
// Return distance between 2 points, stored as 2 pair location;
double dLat = Math.toRadians (lat2 - lat1);
double dLng = Math.toRadians (lng2 - lng1);
double a = Math.sin (dLat / 2) * Math.sin (dLat / 2) + Math.cos (Math.toRadians (lat1))
* Math.cos (Math.toRadians (lat2)) * Math.sin (dLng / 2) * Math.sin (dLng / 2);
double c = 2 * Math.atan2 (Math.sqrt (a), Math.sqrt (1 - a));
double dist = EARTH_RADIOUS * c;
return new Double (dist * METER_CONVERSION) .floatValue ();
}
If you want to get the radius of the area shown on the screen, you just need to divide by 2.
I hope this will be helpful!