Skip to content

Instantly share code, notes, and snippets.

@FabiolaRamirez
Created October 26, 2018 19:48
Show Gist options
  • Select an option

  • Save FabiolaRamirez/e6cbacda8a5ef84aff70d7023b889e7f to your computer and use it in GitHub Desktop.

Select an option

Save FabiolaRamirez/e6cbacda8a5ef84aff70d7023b889e7f to your computer and use it in GitHub Desktop.
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