宽窄优行-由【嘉易行】项目成品而来
无故事王国
2023-05-25 dc1998fc1ac124f6b9a0e434ccf91103dd936409
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
//  YYMapViewManagerViewModel.swift
//  OKProject
//
//  Created by alvin_y on 2020/6/5.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
import RxCocoa
import RxSwift
 
class YYMapViewManagerViewModel: YYViewModel {
    
    /// 预计行驶时间
    let time = BehaviorRelay<String>(value: "大约行驶0分钟")
    
    /// 选择地点和终点后获取预计行驶时长
    func queryExpectedTime() {
        guard let originInfo = YYMapViewManager.share.originInfo.value,let destination = YYMapViewManager.share.destination.value else {return}
        APIManager.shared.provider.rx
            .request(.queryExpectedTime(slat: originInfo.lat, slon: originInfo.lon, elat: destination.lat, elon: destination.lon))
            .map(YYModel<ExpectedTimeModel>.self)
            .validate()
            .subscribe(onSuccess: {[unowned self]  (model) in
                guard let data = model.data else{return}
                self.time.accept("大约行驶\(data.minute)分钟")
            }) {  (error) in
            }
            .disposed(by: disposeBag)
    }
}