ios - Render a MKPolyline in a UIImage -


i need render mkpolyline in uiimage without use of mkmapview if possible (for performances reasons mainly, want display path possible, while map screenshotter provides asynchronously map, app strava does).

i came piece of code:

func pathimageforsize(size: cgsize) -> uiimage {     let region = regionforpath() // mkcoordinateregion     let coordinates = locations.map { $0.coordinate }     uigraphicsbeginimagecontextwithoptions(size, false, uiscreen.mainscreen().scale)      let context = uigraphicsgetcurrentcontext()      cgcontextsetstrokecolorwithcolor(context, uicolor.palette_maincolor().cgcolor)     cgcontextsetlinewidth(context, 4.0)     cgcontextbeginpath(context)      let origin = cgpoint(x: region.center.latitude - region.span.latitudedelta / 2, y: region.center.longitude - region.span.longitudedelta / 2)      (index, coordinate) in coordinates.enumerate() {         let point = cgpoint(x: ((cgfloat(coordinate.latitude) - origin.x) / cgfloat(region.span.latitudedelta)) * size.width,                             y: ((cgfloat(coordinate.longitude) - origin.y) / cgfloat(region.span.longitudedelta)) * size.height)          if index == 0 {             cgcontextmovetopoint(context, point.x, point.y)         } else {             cgcontextaddlinetopoint(context, point.x, point.y)         }     }      cgcontextstrokepath(context)      let image = uigraphicsgetimagefromcurrentimagecontext()     uigraphicsendimagecontext()     return image } 

the code rescales coordinates , draws them coregraphics. path drawn, it's rotated 90 degrees, can see here:

polyline rendered mapkit: mapkit polyline

polyline rendered code: coregraphics polyline

any idea on i'm doing wrong?

i suspect because you're using latitude 'x' , longitude 'y'. latitude vertical dimension (on map north @ top) , longitude horizontal dimension.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -