While driving I record the different coordinates during the drive. If I drive between two points that is generally in a straight line, then the map span of the following code works well but if I drive around the block then the map span doesn't show the route. I can generally see that since I am using the first and last coordinate this would be why. The region is then put into a snapshot to generate an image of the map. What I'm struggling with is being able to use all coordinates to calculate the needed span.
//calculate region
let span = MKCoordinateSpan.init(latitudeDelta: fabs(startCoord.latitude - endCoord.latitude) * 1.6, longitudeDelta: fabs(endCoord.longitude - startCoord.longitude) * 1.6)
let resd = CLLocationCoordinate2D.init(latitude: startCoord.latitude - (startCoord.latitude - endCoord.latitude) * 0.5, longitude: startCoord.longitude + (endCoord.longitude - startCoord.longitude) * 0.5)
let options = MKMapSnapshotter.Options()
options.scale = UIScreen.main.scale
options.region = MKCoordinateRegion.init(center: resd, span: span);
options.size = CGSize(width: 600, height: 450) //map size
options.showsBuildings = true
options.showsPointsOfInterest = true
I found this bit of code on another question
func regionFor(coordinates coords: [CLLocationCoordinate2D]) -> MKCoordinateRegion {
var r = MKMapRect.null
for i in 0 ..< coords.count {
let p = MKMapPoint(coords[i])
r = r.union(MKMapRect(x: p.x, y: p.y, width: 0, height: 0))
}
return MKCoordinateRegion(r)
}
But I couldn't get it to work to show the circle either. Anyone have an idea of how I could do this?