Как перемещать карту при перемещении пользователя по полилинии так же, как карта навигации Apple - PullRequest
0 голосов
/ 07 октября 2019

Я хочу добавить функцию навигации по направлению в одном из моих приложений, так же как и у карты навигации Apple, но застрял, чтобы показать инструкции маршрута / пути при перемещении пользователя, а также не в состоянии обрабатывать уровень масштабирования карты при перемещении пользователя по пути.

Я использую метод ddidEnterRegion, чтобы показать инструкции маршрута, но он не вызывается каждый раз. также для отображения карты в центре, когда пользователь перемещается, я перемещаю текущее местоположение в центре каждый раз, когда пользователь меняет свое местоположение

 func locationManager(_ manager: CLLocationManager, 
        didUpdateLocations locations: [CLLocation]) {
           guard let currentLocation = locations.first else { 
       return 
     }
    if currentCoordinate == nil{
        currentCoordinate = currentLocation.coordinate
        mapView.userTrackingMode = .followWithHeading
    }
     //Zoom to user location
        if let userLocation = locationManager.location?.coordinate{
            let viewRegion = MKCoordinateRegion(center: 
         userLocation, span: MKCoordinateSpan(latitudeDelta: 0.001, 
           longitudeDelta: 0.001))

            mapView.setRegion(viewRegion, animated: false)
        }

      }


   func locationManager(_ manager: CLLocationManager,didEnterRegion region: CLRegion) {
    print("ENTERED")
    stepCounter += 1
    if stepCounter < steps.count {
        let currentStep = steps[stepCounter]
        print(currentStep.polyline.coordinate)
        let message = "In \(currentStep.distance) meters, \(currentStep.instructions)"
        directionsLabel.text = message
        self.setImageAccordingToDirection(instruction: message)
        let speechUtterance = AVSpeechUtterance(string: message)
        speechSynthesizer.speak(speechUtterance)
    } else {
        let message = "Arrived at destination"
        directionsLabel.text = message
        btnStart.backgroundColor = #colorLiteral(red: 0.239351511, green: 0.7106230855, blue: 0.2888338268, alpha: 1)
        btnStart.setImage(#imageLiteral(resourceName: "Right click"), for: .normal)
        btnStart.tag = 2
        let speechUtterance = AVSpeechUtterance(string: message)
        speechSynthesizer.speak(speechUtterance)
        stepCounter = 0
        locationManager.monitoredRegions.forEach({ self.locationManager.stopMonitoring(for: $0) })
        self.sendDataToBLE()
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...