Swift筛选对象数组中包含的相同位置坐标

我正在从服务器接收对象数组中的商店信息列表。 以下是一个示例 –

"stores": [ { "name": “Store 1”, "number": "5381", "country": "BELGIE", "latLng": [ 50.730614, 4.231847 ] }, { "name": "Store 2”, "number": "5220", "country": "BELGIE", "latLng": [ 50.730614, 4.231847 ] }, { "name": "Store 3”, "number": "3982”, "country": "BELGIE", "latLng": [ 50.7315706, 4.2303477 ] }, { "name": "Store 4”, "number": "4179", "country": "BELGIE", "latLng": [ 50.7262577, 4.245589 ] }] 

我在想什么? :我需要过滤掉数组中具有相同latLng值的商店。

为什么? 我需要确定这些“相同的latLng”的值,并添加一个像纬度值0.001的某个值的偏移量,以便当我在地图上显示这些商店时,同一位置上的商店并排显示。

我发现这个 ( Rob B的回答)作为这种方法的参考。

我需要的?
1.如何过滤数组中的对象内的值? 我在for循环中尝试了这样的东西 –

 print("\(allStoresInfo.filter({ $0.latLng![0] == $0.latLng![0] }).count)") This value always returns 4. I know I am missing some basic sense here but need know what it is :-( 
  1. 我过滤并添加相同的值的偏移量后,如何更新我的数组与这些更新的值?

以下方法适当修改每个商店的纬度与另一个商店的纬度相匹配:

 allStoresInfo.map{ currentStore in allStoresInfo.filter{$0.latLng![0] == currentStore.latLng![0]}.enumerated().forEach{ index, matchingStore in matchingStore.latLng![0] += Double(index)*0.001 } } 

只是一小块build议:不要将经度值存储在数组中。 为它们创build一个结构体/类或者使用一个元组来存储它们。