Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.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
mysql中的道路距离计算_Mysql - Fatal编程技术网

mysql中的道路距离计算

mysql中的道路距离计算,mysql,Mysql,我试图沿着距离原点的道路距离(海得拉巴坐标-17.3850,78.4867)获取站点。通过下面的查询,我得到了距离,但它是空中距离。我需要路边的距离 我的sql: SELECT latitude, longitude,Station_Name, Station_Key, (6371 * 2 * ASIN(SQRT( POWER(SIN((17.3850 - ABS(latitude)) * PI()/180 / 2), 2) + COS(17.38

我试图沿着距离原点的道路距离(海得拉巴坐标-17.3850,78.4867)获取站点。通过下面的查询,我得到了距离,但它是空中距离。我需要路边的距离

我的sql:

SELECT latitude, longitude,Station_Name, Station_Key,
(6371 * 2 * ASIN(SQRT(
            POWER(SIN((17.3850 - ABS(latitude)) * PI()/180 / 2),
            2) + COS(17.3850 * PI()/180 ) * COS(ABS(latitude) *
            PI()/180) * POWER(SIN((78.4867 - longitude) *
            PI()/180 / 2), 2) ))) AS distnce
FROM abrs_stations

因此,任何人都可以让我知道如何实现这一点。提前感谢。

空中距离是您唯一可以用现有数据计算的东西。如果您只需要知道距海得拉巴的道路距离(而不是确切的路径),那么您可以在数据库中找到每个位置的道路距离(例如使用谷歌地图),并将其存储在数据库中。如果您想动态地确定道路距离,那么您必须寻找一个API(可能是Google Maps API),该API提供两个坐标之间的道路距离


无论哪种方式,您都不能完全用SQL来完成。

您可以使用google API来查找两个lat-long之间的距离

使用此url,您可以从中获得响应,从而获得距离

    $url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" . $from_latitude . "," . $from_longitude . "&destinations=" . $destination_latitude . "," . $destination_longitude . "&mode=driving&language=pl-PL";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $response = curl_exec($ch);
    curl_close($ch);

    $response_a = json_decode($response, true);

  $distance=  $dist = $response_a['rows'][0]['elements'][0]['distance']['text'];

这里
$distance
是你在两个lat之间的距离,通过
谷歌API

看看谷歌地图API(或其他竞争API)。你如何从经纬度坐标获得路边距离?@Manav:如果我知道如何获得,那么我会为这篇文章写答案。
    $url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" . $from_latitude . "," . $from_longitude . "&destinations=" . $destination_latitude . "," . $destination_longitude . "&mode=driving&language=pl-PL";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $response = curl_exec($ch);
    curl_close($ch);

    $response_a = json_decode($response, true);

  $distance=  $dist = $response_a['rows'][0]['elements'][0]['distance']['text'];