【问题标题】:'Rounding' lat/long coordinates to a 1km radius“四舍五入”纬度/经度坐标到 1 公里半径
【发布时间】:2015-07-28 19:55:43
【问题描述】:

我试图弄清楚如何获取一组坐标(例如:35.7410435、-78.721417)并将它们“四舍五入”或简化为一组坐标,即一组直径为 1 公里的坐标围绕给定点。

基本上,我要做的是从应用中的用户获取地理位置数据,然后发回与他们的位置相对应的数据。但是为了使缓存有效,我需要将接收到的坐标简化为特定的小数位数,以便彼此相距 1000 英尺的人将获得相同的数据,但是当你离得足够远时(我认为 1 公里就足够了),我们将向他们发送“新”数据。

我不确定将收到的坐标四舍五入到最接近的 2 位小数是准确的还是正确的做法。我想这比这更复杂。我找到了不同的答案来计算点之间的距离,但没有得到围绕某个点 1 公里的圆的坐标。

【问题讨论】:

    标签: geolocation coordinates


    【解决方案1】:
    public LatLng onePointFromCircle(LatLng centre, double radius) {
        Log.d(TAG + "one point", radius + "");
        ArrayList<LatLng> points = new ArrayList<LatLng>();
    
        double EARTH_RADIUS = 6378100.0;
        // Convert to radians.
    
        double lat = centre.latitude * Math.PI / 180.0;
        double lon = centre.longitude * Math.PI / 180.0;
    
        for (double t = 0; t <= Math.PI * 2; t += 0.3) {
            // y
            double latPoint = lat + (radius / EARTH_RADIUS) * Math.sin(t)/ Math.cos(lat);
            // x
            double lonPoint = lon + (radius / EARTH_RADIUS) * Math.cos(t)/ Math.cos(lat);
    
    //      d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2))
            Log.d("latpoint",latPoint+"");
            Log.d("lonPoint",lonPoint+"");
    
            // saving the location on circle as a LatLng point
            LatLng point = new LatLng(latPoint * 180.0 / Math.PI, lonPoint
                    * 180.0 / Math.PI);
    
            // here mMap is my GoogleMap object
            // mMap.addMarker(new MarkerOptions().position(point));
            // now here note that same point(lat/lng) is used for marker as well
            // as saved in the ArrayList
            points.add(point);
        }
    
    
        return points.get(1);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      • 2015-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多