linq,js GroupBy 坐标(纬度,经度)

linq,js GroupBy coordinates(lat, lng)

我有以下数组:

var coord = [
{flat:"7", house:"14", indication1: "60", lat: "47.93896450", lng:"33.43282100"},
{flat:"9", house:"18", indication1: "65", lat: "47.87736800", lng:"33.27488850"},
{flat:"10", house:"14", indication1: "24", lat: "47.93896450", lng:"33.43282100"},
{flat:"11", house:"14", indication1: "11", lat: "47.93896450", lng:"33.43282100"},
{flat:"12", house:"14", indication1: "56", lat: "47.93896450", lng:"33.43282100"}];

我想使用 linq.js 按两个字段对这些数组进行分组:latlng

var h = Enumerable.From(data).GroupBy(
            "{lat: $.lat, lng: $.lng}",
            "{ House: $.house, Flat: $.flat }",
            "{ Qlat: $.lat, Qlng: $.lng, info: $$.ToArray()}").ToArray();

console.log(h);

我预计会看到 2 组,但全部看到了 5 组。我哪里错了?

您使用对象进行分组。每个新生成的对象都是一个新对象,不等于最后一个或任何其他对象。

第一个参数可以是null,第四个参数是带分组信息的字符串

var coord = [{ flat: "7", house: "14", indication1: "60", lat: "47.93896450", lng: "33.43282100" }, { flat: "9", house: "14", indication1: "65", lat: "47.87736800", lng: "33.27488850" }, { flat: "10", house: "14", indication1: "24", lat: "47.93896450", lng: "33.43282100" }, { flat: "11", house: "14", indication1: "11", lat: "47.93896450", lng: "33.43282100" }, { flat: "12", house: "14", indication1: "56", lat: "47.93896450", lng: "33.43282100" }],
    grouped = Enumerable.From(coord).GroupBy(
        null,
        "{ House: $.house, Flat: $.flat }",
        "{ Qlat: $.lat, Qlng: $.lng, info: $$.ToArray()}",
        "$.lat + '|' + $.lng"
    ).ToArray();

console.log(grouped);
.as-console-wrapper { max-height: 100% !important; top: 0; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/linq.js/2.2.0.2/linq.js"></script>