MKPolyline broken when using type satelliteFlyover?
I had a similar problem, and I found that the MKMultiPolylineRenderer in iOS 13 is much better for handling polylines on a flyover MapType. You need to do prepare all of your polylines in an array so you have ALL polylines available:
var multiArray = [MKPolyline]()
// CREATE ALL OF YOUR POLYLINES AND APPEND THEM TO multiArray
view.addOverlay(MKMultiPolyline(multiArray))
Then you need to create a section of code to handle MKMultiPolylines in func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer
. I literally copied my MKPolyline section and just changed any reference from MKPolyline
to MKMultiPolyline
.
IDK what to do if you can't change your target to iOS 13. Both flyover map types exhibit a similar situation before iOS 13. I should note that I don't use dark mode in my app, so I'm not sure if you'll see the same results I did. But this code fixed all of my broken/missing polyline problems.
Drawing MKPolyline to be more accurate
You will get an updated location every time it changes, and you can either build up an array of locations, or store them in a database for later retrieval.
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
// the last location presented here is the current position of the runner
self.locations.append(locations.last)
// store this in a database, or as a class variable
}
You can set the desired accuracy when you initialise your location manager
locationManager.desiredAccuracy = kCLLocationAccuracyBest
and then when you're creating the map, create a line showing the runner's route
let polyline = MKPolyline(coordinates: self.locations, count: self.locations.count)
self.mapView.addOverlay(polyline)
Here's an example of the output - looks like the finish is in the middle of the run, but that's because I was heading back home
Related Topics
Issues While Lightweight Core Data Migration
How to Change Bordercolor When Button.Ishighlighted
Extending Dictionary with Key and Value Constraints
Restrictions Around Protocols and Generics in Swift
Replicate Opengl Blending in Metal
How to Disabled Some Default Functionality in Scene View When Allowscameracontrol = True
How to Create Travelling Wave in Spritekit
Swiftui List .Ondelete: Index Out of Range
Convert Gregorian Date to Hijri Date
Trouble Passing Array Through Prepareforsegue
iOS - Could Not Open Obj File When Convert Mdlasset to Mdlmesh
Swift Running Code in Periodically Background
Swift: Handling an Unexpected Nil Value, When Variable Is Not Optional
Wkwebview - Update HTML Tags from Swiftui Textfields
Protocol Variable Implementing Another Protocol
Osx/Swift: Call a Function When Internet Connection Is Established/Restored
Populate a Multidimensional Array with a Loop
Can't Hide Status Bar in Avplayerviewcontroller's Portrait Mode