| | |
| | | // |
| | | // Services.swift |
| | | // YixiuShop |
| | | // |
| | | // Created by Sweet on 2019/9/30. |
| | | // Copyright © 2019 jackLove. All rights reserved. |
| | | // |
| | | // |
| | | // Services.swift |
| | | // YixiuShop |
| | | // |
| | | // Created by Sweet on 2019/9/30. |
| | | // Copyright © 2019 jackLove. All rights reserved. |
| | | // |
| | | |
| | | import UIKit |
| | | //import RxRelay |
| | | //import RxCocoa |
| | | //import RxDataSources |
| | | import RxSwift |
| | | import Alamofire |
| | | |
| | | //外网测试环境 |
| | | #if DEBUG |
| | | let All_Url = "http://192.168.110.22:8040" |
| | | //内网测试环境 |
| | | //let All_Url = "" |
| | | let Google_Url = "https://roads.googleapis.com/v1" |
| | | #else |
| | | let All_Url = "http://192.168.110.22:8040" |
| | | let Google_Url = "https://roads.googleapis.com/v1" |
| | | #endif |
| | | |
| | | |
| | | class Services: NSObject { |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | class GoogleServices:NSObject{ |
| | | |
| | | enum DirectionType { |
| | | case byPlaceId(String) |
| | | case byAddress(String) |
| | | case byCoordinates(CLLocationCoordinate2D) |
| | | |
| | | func toFormat()->String{ |
| | | switch self { |
| | | case .byPlaceId(let string): |
| | | return String(format: "place_id:%@", string) |
| | | case .byAddress(let string): |
| | | return string |
| | | case .byCoordinates(let coordiante): |
| | | return String(format: "%lf,%lf", coordiante.latitude,coordiante.longitude) |
| | | } |
| | | } |
| | | } |
| | | |
| | | class func directionsLine(origin:DirectionType,destination:DirectionType)->Observable<BaseResponse<GoogleRoteModel>>{ |
| | | let params = ParamsAppender.build(url: Google_Url) |
| | | .interface(url: "/directions/json") |
| | | .append(key: "origin", value: origin.toFormat()) |
| | | .append(key: "destination", value: destination.toFormat()) |
| | | .append(key: "alternatives", value: false) //可供选择方案:会增加请求时间 |
| | | return NetworkRequest.request(params: params.googleMapDone(), method: .post, progress: false) |
| | | } |
| | | |
| | | |
| | | /// When directions line was done , need call the method snap to the road. |
| | | /// - Parameter path: coordiante paths |
| | | class func snapToRoads(path:String)->Observable<BaseResponse<SnappedPointsModel>>{ |
| | | let params = ParamsAppender.build(url: Google_Url) |
| | | .interface(url: "/snapToRoads/") |
| | | .append(key: "path", value: path) |
| | | .append(key: "interpolate", value: true) |
| | | params.params.removeValue(forKey: "appid") |
| | | params.params.removeValue(forKey: "language") |
| | | return NetworkRequest.request(params: params.googleMapDone(), method: .post, progress: false) |
| | | } |
| | | } |