Swift Offset for MKPointAnnotations for same location coordinates at different altitude range

假装没事ソ 提交于 2019-12-11 17:22:07

问题


I have had a problem earlier and that's been answered here. Further, I have one more question where in I tried an approach and that fails.

I need to show two Annotations on a map, that has same location coordinates. Data comes from a service and I applied a logic to add an offset of 0.0001 to the locations with same latitude. (SO Answer)

Now when I zoom-in/zoom-out, I am calculating the altitude using

let updatedRadius = (mapView.camera.altitude)/1000  //in KM

And then, I have the following to maintain a constant offset between to annotations (I mean, the annotations to appear side by side at any zoom level)

switch updatedRadius {
                    case 0 ... 5:
                        allStoresInfo.map { currentStore in allStoresInfo.filter{$0.latLng![0] == currentStore.latLng![0]}.enumerated().forEach{ index, matchingStore in
                            matchingStore.latLng![0] += Double(index)*0.0001
                            }
                        }
                    case 5 ... 10:
                        allStoresInfo.map { currentStore in allStoresInfo.filter{$0.latLng![0] == currentStore.latLng![0]}.enumerated().forEach{ index, matchingStore in
                            matchingStore.latLng![0] += Double(index)*0.001
                            }
                        }
                    case 10 ... 25:
                        allStoresInfo.map { currentStore in allStoresInfo.filter{$0.latLng![0] == currentStore.latLng![0]}.enumerated().forEach{ index, matchingStore in
                            matchingStore.latLng![0] += Double(index)*0.01
                            }
                        }
                    default:
                        allStoresInfo.map { currentStore in allStoresInfo.filter{$0.latLng![0] == currentStore.latLng![0]}.enumerated().forEach{ index, matchingStore in
                            matchingStore.latLng![0] += Double(index)*0.0001
                            }
                        }
                    }

Although this code works, it always applies only the 0.0001 offset. Why offset that's applied is 0.0001 always? Need some help please :-)

来源:https://stackoverflow.com/questions/45610399/swift-offset-for-mkpointannotations-for-same-location-coordinates-at-different-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!