Created
October 26, 2018 19:48
-
-
Save FabiolaRamirez/e6cbacda8a5ef84aff70d7023b889e7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getCoordinates() { | |
| coordinates = [] | |
| let queue = OperationQueue() | |
| let operation1 = BlockOperation { | |
| let geoCoder = CLGeocoder() | |
| for mapPoint in self.points { | |
| let dispatchGroup = DispatchGroup() | |
| dispatchGroup.enter() | |
| print("CurrentAlert.shared.locations.count: \(CurrentAlert.shared.locations.count)") | |
| if let location = CurrentAlert.shared.locations[mapPoint.address] { | |
| self.coordinates.append(location) | |
| dispatchGroup.leave() | |
| } else { | |
| geoCoder.geocodeAddressString(mapPoint.address) { (placemarks, error) in | |
| if let placemarks = placemarks, let location = placemarks.first?.location { | |
| CurrentAlert.shared.locations[mapPoint.address] = CLLocationCoordinate2D(latitude: location.coordinate.latitude , longitude: location.coordinate.longitude) | |
| self.coordinates.append(CLLocationCoordinate2D(latitude: location.coordinate.latitude , longitude: location.coordinate.longitude)) | |
| } else { | |
| self.coordinates.append(nil) | |
| } | |
| dispatchGroup.leave() | |
| } | |
| } | |
| dispatchGroup.wait() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment