Swift Offset for MKPointAnnotations for same locat

2019-08-20 12:13发布

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 :-)

标签: ios swift mapkit
0条回答
登录 后发表回答