There are a few approaches you can take.
1. Read the current viewpoint as a Center and Scale and use the targetGeometry (it will be a point):
let mapCenter = mapView.currentViewpoint(with: .centerAndScale)?.targetGeometry as? AGSPoint
2. Get the UI center (as you were) and convert it to map coordinates:
let mapCenter = mapView.screen(toLocation: mapView.center)
3. Use the visibleArea property to derive the center:
let mapCenter = mapView.visibleArea?.extent.center
In all those cases, the coordinate will be in the map's spatial reference. You'll want to convert them to lat/lon like this:
if let latLon = AGSGeometryEngine.projectGeometry(mapCenter, to: .wgs84()) as? AGSPoint {
let lat = latLon.y
let lon = latLon.x
}
If you find yourself needing latitude and longitude a lot, you can create an extension on AGSPoint:
extension AGSPoint {
var latitude: Double {
return (AGSGeometryEngine.projectGeometry(self, to: .wgs84()) as? AGSPoint)?.y ?? 0
}
var longitude: Double {
return (AGSGeometryEngine.projectGeometry(self, to: .wgs84()) as? AGSPoint)?.x ?? 0
}
}
Note that if you're just using the Lat/Lon for display, you could make use of AGSCoordinateFormatter.LatitudeLongitudeStringFromPoint:format:decimalPlaces:()
As for detecting when there's a new center, there have been a couple of questions about this recently which should help you:
Hope this helps!