Guest User

Untitled

a guest
Jun 25th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  2.  
  3. //user's current location
  4. let nowlocation = locations.last
  5. userLocations.append(nowlocation!)
  6.  
  7. print("HERE IS THE LOCATION ARRAY")
  8. print(userLocations)
  9.  
  10. //show the current location region
  11. let center = CLLocationCoordinate2D(latitude: nowlocation!.coordinate.latitude, longitude: nowlocation!.coordinate.longitude)
  12. let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.7, longitudeDelta: 0.7))
  13. self.mapView.setRegion(region, animated: true)
  14. drawRoute(locationArray: userLocations)
  15. }
  16.  
  17. func drawRoute(locationArray: [CLLocation]) {
  18. if (locationArray.count) > 1 {
  19. var destinationLocIndex = (locationArray.count) - 1
  20. var startLocIndex = (locationArray.count) - 2
  21.  
  22. let destinationloc = locationArray[destinationLocIndex].coordinate
  23. let startLoc = locationArray[startLocIndex].coordinate
  24.  
  25. var routeArray = [startLoc, destinationloc]
  26. //test if the function works well or not
  27. print(routeArray)
  28. var geodesicLine = MKGeodesicPolyline(coordinates: routeArray , count: routeArray.count)
  29. mapView.add(geodesicLine, level: .aboveRoads)
  30.  
  31. }
Add Comment
Please, Sign In to add comment