Created
February 24, 2022 11:33
-
-
Save mzeeshanid/c5ee11295f18569bd746331f1efef681 to your computer and use it in GitHub Desktop.
GMSGeocoder entertain last request only
This file contains 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
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