【问题标题】:Find Longitude & Latitude of another point from first point with given distance.从给定距离的第一个点查找另一个点的经度和纬度。
【发布时间】:2014-05-06 08:32:25
【问题描述】:

我有代码可以找到两个经度和纬度值之间的距离。但是我想在给出公里,第一点的纬度和经度值时跟踪第二点的经度和纬度值。

这是代码,我发现使用它们的纬度和经度值来查找两点之间的距离。

<?php
    function getLatLong($address) {
        $address = str_replace(' ', '+', $address);
        $url = 'http://maps.googleapis.com/maps/api/geocode/json?address='.$address.'&sensor=false';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $geoloc = curl_exec($ch);
        $json = json_decode($geoloc);

        return array($json->results[0]->geometry->location->lat, $json->results[0]->geometry->location->lng);
    }

    $address = getLatLong('Guildford');
    $address = getLatLong('BH15 2BT');
    $address = getLatLong('10 Downing Street, London');

    function Haversine($start, $finish) {
        $theta = $start[1] - $finish[1];

        $distance = (sin(deg2rad($start[0])) * sin(deg2rad($finish[0]))) + (cos(deg2rad($start[0])) * cos(deg2rad($finish[0])) * cos(deg2rad($theta))); 
        $distance = acos($distance); 
        $distance = rad2deg($distance); 
        $distance = $distance * 60 * 1.1515;

        return round($distance, 2);
    }

    $start = getLatLong('Guildford');
    $finish = getLatLong('BH15 2BT'); 
    $distance = Haversine($start, $finish);

    print('<p>The distance between ['.$start[0].', '.$start[1].'] and ['.$finish[0].', '.$finish[1].'] is '.$distance.' miles ('.($distance * 1.609344).' km).</p>');
?>

但是,我需要从第一个点的经纬度和距离中找到第二个点的经纬度。

谢谢

【问题讨论】:

    标签: php google-maps gps


    【解决方案1】:

    This webpage 对这类事情非常有用。

    如果你去那里,你会发现你的新点的纬度由下式给出:

    asin( sin(φ1)*cos(d/R) + cos(φ1)*sin(d/R)*cos(θ) )
    

    新点的经度由下式给出:

    λ1 + atan2( sin(θ)*sin(d/R)*cos(φ1), cos(d/R)−sin(φ1)*sin(φ2) )
    

    其中 φ1 是旧点的纬度,φ2 是新点的纬度,λ1 是旧点的经度,θ 是方位角(以弧度为单位,从北顺时针方向),d 是经过的距离,R 是地球的半径。旧点是指第一个点,即你知道坐标的那个点。

    如果您不知道地球半径,可以使用其平均半径:6371000m(注意单位)或compute an approximation,具体取决于纬度。

    【讨论】:

    • 如果没有,请显示一些您正在使用的数据示例,我会更深入地研究...
    • 是的,我被困住了。我不知道在那里提供什么价值。谢谢
    • 您知道 GPS 或用户从第一个点移动到哪个方向吗?这是方位,应该换算成弧度。
    • 如果你没有这个值,只有一个距离,你的点 2 可能在一个圆上的任何地方。 (距离是这个圆的半径,点 1 是它的中心。)或者您可能有该点必须遵循的道路或路径?
    • 是的,我确实需要整个圈子。实际上,我正在编写的代码是从我的位置到该区域 5 公里范围内寻找用户,是的,这将是从我的角度来看的圆圈。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多