Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
- //user's current location
- let nowlocation = locations.last
- userLocations.append(nowlocation!)
- print("HERE IS THE LOCATION ARRAY")
- print(userLocations)
- //show the current location region
- let center = CLLocationCoordinate2D(latitude: nowlocation!.coordinate.latitude, longitude: nowlocation!.coordinate.longitude)
- let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.7, longitudeDelta: 0.7))
- self.mapView.setRegion(region, animated: true)
- drawRoute(locationArray: userLocations)
- }
- func drawRoute(locationArray: [CLLocation]) {
- if (locationArray.count) > 1 {
- var destinationLocIndex = (locationArray.count) - 1
- var startLocIndex = (locationArray.count) - 2
- let destinationloc = locationArray[destinationLocIndex].coordinate
- let startLoc = locationArray[startLocIndex].coordinate
- var routeArray = [startLoc, destinationloc]
- //test if the function works well or not
- print(routeArray)
- var geodesicLine = MKGeodesicPolyline(coordinates: routeArray , count: routeArray.count)
- mapView.add(geodesicLine, level: .aboveRoads)
- }
Add Comment
Please, Sign In to add comment