Mkpolyline Broken When Using Type Satelliteflyover

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
Sample Image



Related Topics



Leave a reply



Submit