I want to zoom mapview according to giving address with Mapview and I use
let geocoder = CLGeocoder()
var regionInMeterForList : Double = 7500
geocoder.geocodeAddressString(address) {
placemarks, error in
let placemark = placemarks?.first
print(self.address)
let coordinates:CLLocationCoordinate2D = (placemark?.location!.coordinate)!
let region = MKCoordinateRegion.init(center: coordinates, latitudinalMeters: regionInMeterForList, longitudinalMeters: regionInMeterForList)
self.mapVieww.setRegion(region, animated: true)
}
I'm fetching address from server and it has lots of data.My issue is , if addresses doesn't match to map geocode can not find coordinates
Example:
Let's say my adress is "New York City" but in map , its declared as "New York" so when program try to find "New York City" coordinates, it gives error :
optional(Error Domain=kCLErrorDomain Code=8 "(null)")
So, How can I fix if address doesnt match the mapview's declared addresses? or Is there a method that find possible addresses which contains in giving adress?