选择st_distance作为“距离”在谷歌融合表中不起作用

时间:2015-08-18 06:04:00

标签: google-maps google-fusion-tables google-distancematrix-api

ST_DISTANCE AS'距离'在代码下面没有工作:

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";

任何人都可以帮助我如何在别名中获得st_distance?

1 个答案:

答案 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;