谷歌地图v2获取类型为km square的可见区域

时间:2014-04-01 13:15:22

标签: android google-maps latitude-longitude area

我试图找到屏幕上可见的区域。我可以找到屏幕的边界,但我无法计算公里方形的面积?有没有可能的计算方法?

googleMap.setOnCameraChangeListener(new OnCameraChangeListener() {
        @Override
        public void onCameraChange(CameraPosition position) {
            LatLngBounds bounds = googleMap.getProjection().getVisibleRegion().latLngBounds;
            getAreaInTheScreen(bounds);
        }

        private double getAreaInTheScreen(LatLngBounds bounds) {
                double northLat=bounds.northeast.latitude;
                double northLong=bounds.northeast.longitude;
                double southLat=bounds.southwest.latitude;
                double southLong=bounds.southwest.longitude;


                    /// it must return an area

                return area;
        }
    });

1 个答案:

答案 0 :(得分:2)

当然可以。 你有所有需要的信息。 所以首先你应该计算从一个点到另一个点的距离,比如说 SouthWest和SouthEast。 southWest坐标(southLat,south Long) 东南坐标(southLat,northLong),纬度保持不变。

Location l = new Location("southwest");
l.setLatitude(southLat);
l.setLongitude(southLong);
Location l2 = new Location("southeast");
l.setLatitude(southLat);
l.setLongitude(northLong);
double height = l.distanceTo(l2);

同样的事情将是矩形的宽度,点将是SouthWest和NorthWest

西南坐标(southLat,southLong) 西北坐标(northLat,southLong),经度保持不变。 我们可以使用第一个位置对象“l”导致点数相同。

Location l3 = new Location("northwest");
l3.setLatitude(northLat);
l3.setLongitude(southLong);
double width = l.distanceTo(l3);

double area = width*height;

很抱歉,如果出现某种语法错误,我正在使用手机