Skip to content

Instantly share code, notes, and snippets.

@mzeeshanid
Created February 24, 2022 11:33
Show Gist options
  • Save mzeeshanid/c5ee11295f18569bd746331f1efef681 to your computer and use it in GitHub Desktop.
Save mzeeshanid/c5ee11295f18569bd746331f1efef681 to your computer and use it in GitHub Desktop.
GMSGeocoder entertain last request only
class ReverseGeoCodingViewModel {
var requestIdentifier: Int = 0
func reverseGeoCodeLocation(_ coordinate: CLLocationCoordinate2D,
completion: @escaping GMSReverseGeocodeCallback) {
self.requestIdentifier += 1
let currentRequestIdentifier = self.requestIdentifier
let geocoder = GMSGeocoder()
geocoder.reverseGeocodeCoordinate(coordinate) { response, error in
guard currentRequestIdentifier >= self.requestIdentifier else {
return
}
completion(response, error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment