How to draw routes that aren't on roads, MKMapView

佐手、 提交于 2019-12-06 06:27:42

Try using the site to create the gpx file.

Also note that Xcode only uses the tag so if you find a tool that generates <rte> or <trk> based gpx files, Xcode won't be able simulate your location properly. So in the file that the linked web site creates you need to change <trkpt> to <wpt>. This code below might help with getting the polyline.

func addRoute() {
  let thePath = NSBundle.mainBundle().pathForResource("Route", ofType: "gpx") // Not sure on this part
  let pointsArray = NSArray(contentsOfFile: thePath!)

  let pointsCount = pointsArray!.count

  var pointsToUse: [CLLocationCoordinate2D] = []

  for i in 0...pointsCount-1 {
    let p = CGPointFromString(pointsArray![i] as! String)
    pointsToUse += [CLLocationCoordinate2DMake(CLLocationDegrees(p.x), CLLocationDegrees(p.y))]
  }

  let myPolyline = MKPolyline(coordinates: &pointsToUse, count: pointsCount)

  mapView.addOverlay(myPolyline)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!