【问题标题】:Php formulae to calculate new lat long position to specific distancePhp公式计算新的经纬度到特定距离的位置
【发布时间】:2013-09-24 12:47:34
【问题描述】:

我有一个纬度和经度点。现在我需要将它们移动到地图上的任何方向 0.25 英里。我正在使用谷歌地图。我想在 php 中执行此操作。我想要这样做的原因是不能准确地定位到用户提交的地址,而是在几距离之外争夺。是否有任何算法可用于此类任务?

【问题讨论】:

    标签: php google-maps gis


    【解决方案1】:

    希望我没有遗漏任何括号

    $fromLatitude = 51.5171;
    $fromLongitude = -0.1062;
    
    echo $fromLatitude, ' - ', $fromLongitude, PHP_EOL;
    
    $distanceInMetres = 250;
    $bearing = 0;
    
        $earthMeanRadius = 6371009.0; // metres
    
        $destinationLatitude = rad2deg(
            asin(
                sin(deg2rad($fromLatitude)) *
                    cos($distanceInMetres / $earthMeanRadius) +
                cos(deg2rad($fromLatitude)) *
                    sin($distanceInMetres / $earthMeanRadius) *
                    cos(deg2rad($bearing))
            )
        );
        $destinationLongitude = rad2deg(
            deg2rad($fromLongitude) +
            atan2(
                sin(deg2rad($bearing)) *
                    sin($distanceInMetres / $earthMeanRadius) *
                    cos(deg2rad($fromLatitude)),
                cos($distanceInMetres / $earthMeanRadius) -
                    sin(deg2rad($fromLatitude)) * sin(deg2rad($destinationLatitude))
            )
        );
    
    echo $destinationLatitude, ' - ', $destinationLongitude, PHP_EOL;
    

    【讨论】:

      【解决方案2】:

      您可以计算 delta Lat 和 delta Lon。一个纬度总是 111 公里,赤道上方的经度也是 111 公里,其他任何地方都更小。 1°经度的长度取决于纬度。维基百科上有一个公式。

      【讨论】:

        【解决方案3】:

        您可以在这里找到一个简单的 JavaScript 实现:http://www.movable-type.co.uk/scripts/latlong.html

        您需要向下滚动到“给定距离和距起点的方位角的目标点”,您会在此处找到有关如何执行此操作的 JavaScript。但是,您确实需要将轴承作为公式的参数。很抱歉它不是PHP实现,但我想它可以转换。

        <!-- use this to use the Geo object -->
        <script src="http://www.movable-type.co.uk/scripts/geo.js"></script>
        <script>
          function orthoDestMap() {
            // eg. 53°19′14″N
            var lat1 = Geo.parseDMS($('#ortho-dest .lat1').val());
        
            // eg. 001°43′47″W
            var lon1 = Geo.parseDMS($('#ortho-dest .lon1').val());
        
            // eg. 096°01′18″
            var brng = Geo.parseDMS($('#ortho-dest .brng').val());
        
            // In kilometers
            var dist = 111;
        
            var p1 = new LatLon(lat1, lon1);
            var p2 = p1.destinationPoint(brng, dist);
        
            // New latitude and longitude
            lat2 = p2.lat();
            lon2 = p2.lon();
          }
        </script>
        

        【讨论】:

        • 是的,我想获得新的经度,也就是说在任何方向上与当前经度的距离为 x 英里
        猜你喜欢
        • 1970-01-01
        • 2011-04-20
        • 2021-05-10
        • 2010-09-06
        • 2014-12-16
        • 2011-12-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多