Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 查找经度&;从给定距离的第一个点到另一个点的纬度。_Php_Google Maps_Gps - Fatal编程技术网

Php 查找经度&;从给定距离的第一个点到另一个点的纬度。

Php 查找经度&;从给定距离的第一个点到另一个点的纬度。,php,google-maps,gps,Php,Google Maps,Gps,我有代码可以找到两个经度和纬度值之间的距离。但我想在给定公里数、第一个点的纬度和经度值时,跟踪第二个点的经度和纬度值 这是代码,我发现使用纬度和经度值来查找两点之间的距离 <?php function getLatLong($address) { $address = str_replace(' ', '+', $address); $url = 'http://maps.googleapis.com/maps/api/geocode/json?ad

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

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

<?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>');
?>

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

谢谢

对这类事情非常有用

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

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) )
新点的经度由下式给出:

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是地球的半径。我指的是第一个点,你知道坐标的那个点


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

如果不知道,请显示您正在使用的一些数据示例,我将更深入地了解……是的,我被轴承卡住了。我不知道这里面有什么价值。谢谢你知道gps或用户从第一个点向哪个方向移动吗?这是方位角,它应该被转换成弧度。如果你没有这个值,只有一个距离,你的点2可以是圆上的任何地方。(距离是这个圆的半径,点1是它的中心。)或者你有一条路或路径,点必须遵循?是的,我需要整个圆。实际上,我正在编码的是从我的位置到该区域5公里范围内的用户,是的,这将是从我的点开始的圆圈。谢谢