bing地图按距离对搜索结果进行排序

问题描述 投票:0回答:1

每当用户加载地图时,我都会使用Bing Maps的QueryAPIManager加载位置数据。

结果是按数据库中的输入顺序(字母顺序)而不是按距离(不方便用户)加载到界面中的。如何使结果按距地图中心或指定点的距离排序?

这是我所拥有的:

function getLocationsOnChangeView() {        
    //Create a query to get data that intersects the bounds of the map.
    var queryOptions = {
        queryUrl: dataSourceUrl,
        top: 250,
        spatialFilter: {
            spatialFilterType: 'intersects',
            intersects: map.getBounds()
        },
    };

    Microsoft.Maps.SpatialDataService.QueryAPIManager.search(queryOptions, map, function (data) {

        for (var i = 0; i < data.length; i++) {
            data[i].setOptions({
                icon: 'images/pin-black.png',
                text: (i + 1) + '',

            });
        }

        //Add results to the map.
        pushpinLayer.add(data);

    });
}

我也尝试过使用“附近”过滤器:

    var queryOptions = {
        queryUrl: dataSourceUrl,
        top: 250,
        spatialFilter: {
            spatialFilterType: 'intersects',
            location: map.getCenter()
            radius: 500
        },
    };

但是这仍然不能按距离排序。

这必须使用Javascript完成,还是Bing模块可以做到这一点?

sorting geolocation location bing-maps bing
1个回答
0
投票

目前正在使用:

        var dataDistanceSort = [];

        for (var i = 0; i < data.length; i++) {
            dataDistanceSort.push(data[i])
        }

        dataDistanceSort.sort(function(a, b){
            if(a.metadata.__Distance < b.metadata.__Distance) { return -1; }
            if(a.metadata.__Distance > b.metadata.__Distance) { return 1; }
            return 0;
        })
© www.soinside.com 2019 - 2024. All rights reserved.