2017-09-26 88 views
-2

我試圖從原點(海德拉巴德座標-17.3850,78.4867)和道路距離一起取站點。用下面的查詢得到距離,但它是空中距離。我需要路邊距離。mysql中的道路距離計算

我的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 

所以任何一個可以請讓我知道如何做到這一點。提前致謝。

+0

看看谷歌地圖API(或其他競爭性的API)。 – David

+0

如何從經緯度座標獲得路邊距離? – Manav

+0

@Manav:如果我知道如何得到那個,那麼我會爲這篇文章寫回答。 – Sucharitha

回答

0

您可以使用此網址你從那裏你可以得到你的距離響應使用谷歌API用於查找距離的兩個緯度長

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

之間 。

$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是兩者之間你的距離緯度長,google API

1

空中距離是你可以用你所擁有的數據計算的唯一東西。如果您只需知道海德拉巴的道路距離(而不是確切的路徑),那麼您可以找出數據庫中每個位置的道路距離(例如使用Google地圖)並將其存儲在數據庫中。如果你想動態確定道路距離,那麼你必須尋找一個API(也許是Google Maps API),它可以給你兩個座標之間的道路距離。

無論哪種方式,你不能純粹在SQL中。