-1

ST_DISTANCE AS「距離」不是下面的代碼工作:選擇st_distance爲「距離」在谷歌的融合表不工作

var query = "SELECT 'Coordinates' as 'Coordinates', " + 
    "'Lender_Name' as 'Lender_Name', " + 
    "'ZIP_Code' as 'ZIP_Code' , " + 
    "ST_DISTANCE('Coordinates', 'LATLNG(" + lat + " " + long + ")') AS 'distance' " + 
    " FROM " + tableid + " ORDER BY ST_DISTANCE(Coordinates, LATLNG(" + lat + "," + long + ")) LIMIT 5"; 

當我使用沒有ST_DISTANCE因爲距離它的正常工作對我來說:

var query = "SELECT 'Coordinates' as 'Coordinates', " + 
    "'Lender_Name' as 'Lender_Name', " + 
    "'ZIP_Code' as 'ZIP_Code' " + 
    " FROM " + tableid + " ORDER BY ST_DISTANCE(Coordinates, LATLNG(" + lat + "," + long + ")) LIMIT 5"; 

Can任何人都可以幫助我如何獲得st_distance的別名?

+1

請指定「不工作」的含義。 –

+0

嗨吉姆, \t \t \t \t感謝您的快速回復。 \t \t \t \t其實我正在努力使用lat long獲得兩個位置之間的距離。 \t \t \t \t當我使用以下查詢獲取距離時,它不適合我。 \t \t \t \t 「ST_DISTANCE( '座標', '經緯度(」 +緯度+ 「」 +長+ 「)')AS '距離'」 + \t \t \t \t能否請你幫我聽到或建議我任何其他選項。如何計算兩個位置之間的距離。 –

+0

我想計算兩個位置之間的距離,你能幫我嗎? –

回答

0

我已經通過以下代碼實現瞭解決方案。

function initialize() { 
     //CONVERT THE MAP DIV TO A FULLY-FUNCTIONAL GOOGLE MAP 
     var mapOptions = { 
      zoom: 8, 
      center: new google.maps.LatLng(-34.397, 150.644), 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     } 
     var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 


     var output = '<tr><th scope="col">From</th><th scope="col">To</th><th scope="col">Miles</th></tr>'; 


     var currZipCode = 99929; 
     currZipCode = currZipCode.toString(); 

     var destinationZipCode = 99803; 
     destinationZipCode = destinationZipCode.toString(); 

     calcMileage(); 
     function calcMileage() {     

      var service = new google.maps.DistanceMatrixService(); 
      service.getDistanceMatrix({ 
        origins:  [ currZipCode ], 
        destinations: [ destinationZipCode ], 
        travelMode: google.maps.TravelMode.DRIVING, 
        unitSystem: google.maps.UnitSystem.IMPERIAL 
       }, function(response, status) {     
        if(status == google.maps.DistanceMatrixStatus.OK) { 
         var tempDistance = response.rows[0].elements[0].distance.text; 
        } else { 
         var tempDistance = 'ERROR'; 
        }    
        //STORE CURRENT OUTPUT AND GET THE NEXT DESTINATION   
        output += '<tr><td>' + currZipCode + '</td><td>' + destinationZipCode + '</td><td>' + tempDistance + '</td></tr>';     

        displayResults();   
       } 
      ); 
      function displayResults() {   
       document.getElementById('zip_code_output').innerHTML = '<table cellpadding="5">' + output + '</table>';  
      }    
     } 
    } 

    function loadScript() {  
     var script = document.createElement("script");  
     script.type = "text/javascript";  
     script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize"; 
     document.body.appendChild(script); 
    } 
    //START THE SCRIPT (AFTER THE PAGE LOADS) 
    window.onload = loadScript;