我从几个回复中找到了 Google Map API v2 的解决方案:
stackoverflow#1 和
stackoverflow#2
所以,需要从GoogleMap.OnCameraChangeListener接口实现Activity
私有静态最终 int REQUEST_CODE_GOOGLE_PLAY_SERVECES_ERROR = -1;
私有静态最终双 EARTH_RADIOUS = 3958.75; //地球半径;
私有静态最终 int METER_CONVERSION = 1609;
私人谷歌地图 mGoogleMap;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext);
如果(状态!= ConnectionResult.SUCCESS)
{
对话框对话框 = GooglePlayServicesUtil.getErrorDialog(状态,活动,
REQUEST_CODE_GOOGLE_PLAY_SERVECES_ERROR);
对话框.show();
mGoogleMap = null;
}
别的
{
mGoogleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(
R.id.fragment_shops_layout_maps_fragment)).getMap();
mGoogleMap.setOnCameraChangeListener(this);
}
}
监听器,在地图缩放时工作。确定显示在屏幕上的地图左下角、右下角、左上角和右上角的位置为LatLng。通过屏幕的最大边和两个点,我们可以得到地图中心的半径。
@Override
公共无效 onCameraChange(CameraPosition cameraPosition)
{
// 缩放监听器;
浮动 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("距离:","距离宽度:" + dist_w +" 距离高度:" + dist_h);
}
返回 2 点之间的距离,以米为单位存储为 2 对位置;
公共双距离从(双 lat1,双 lng1,双 lat2,双 lng2)
{
// 返回 2 个点之间的距离,存储为 2 对位置;
双 dLat = Math.toRadians(lat2 - lat1);
双 dLng = Math.toRadians(lng2 - lng1);
双 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);
双 c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
双距离 = EARTH_RADIOUS * c;
return new Double(dist * METER_CONVERSION).floatValue();
}
如果你想得到区域半径,屏幕上显示的区域只需要除以 2。
希望对你有用!