简体   繁体   English

计算Google地图中可见地图用户的半径

[英]Calculate radius of visible map user in Google map

What I want to do is calculate a circle's radius by which the user is viewing the map. 我想要做的是计算用户查看地图所用的圆的半径。
I've written the solution so far as follows (which is true): 到目前为止,我已经编写了解决方案(这是正确的):

mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
        @Override
        public void onCameraChange(CameraPosition cameraPosition) {
            String TAG = AppController.TAG;
            LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
            LatLng target = cameraPosition.target;
            LatLng northEast = bounds.northeast;
            LatLng southEast = bounds.southwest;
            float[] results1 = new float[1];
            float[] results2 = new float[1];
            Location.distanceBetween(target.latitude, target.longitude, northEast.latitude, northEast.longitude, results1);
            Location.distanceBetween(target.latitude, target.longitude, southEast.latitude, southEast.longitude, results2);
            double distance = results1[0] > results2[0] ? results1[0] : results2[0];
            Log.d(TAG, "onCameraChange:" + results1[0] + "  " + results2[0]);
        }
    });

I'm facing two questions here: 我在这里面临两个问题:
1- First of all why the distane between the center and north east isn't equal to south west? 1-首先,为什么中心与东北之间的距离不等于西南?
2- Is there any built in method to achieve the same result? 2-是否有内置方法可以达到相同的结果?

在此处输入图片说明

as you can see from the map above, the horizontal line (latitude) gets shorter the further away you get from the equator. 从上面的地图可以看到,离赤道越远,水平线(纬度)越短。

on the screen, the map is 'distorted' to flatten the curved surface of the earth, with +/- the same amount of longitude and latitude from the center of the view. 在屏幕上,地图会“扭曲”以平整地球的曲面,并且距离视图中心的经度和纬度为+/-相同。

so unless you are taking measurements directly at the equator, you will have slight differences in the radius. 因此,除非您直接在赤道处进行测量,否则半径将略有不同。 for small distances, this is negligible. 对于小距离,这可以忽略不计。

if accuracy is not important, you can try using the smaller radius (if you want to draw a circle on the view that will not be partially hidden), or use the bigger radius (if you want to do calculations for places within that cicle). 如果精度不重要,则可以尝试使用较小的半径(如果要在视图上绘制一个不会被部分隐藏的圆),或者可以使用较大的半径(如果要计算该cicle中的位置) 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM