| | |
| | | map.isBuildingsEnabled = true |
| | | map.settings.compassButton = true |
| | | map.settings.myLocationButton = false |
| | | map.setMinZoom(5, maxZoom: 20) |
| | | // map.setMinZoom(5, maxZoom: 20) |
| | | map.accessibilityElementsHidden = true |
| | | map.delegate = self |
| | | return map |
| | | }() |
| | | |
| | | private lazy var mananger:CLLocationManager = { |
| | | lazy var mananger:CLLocationManager = { |
| | | let manan = CLLocationManager() |
| | | manan.delegate = self |
| | | manan.requestWhenInUseAuthorization() |
| | | manan.requestAlwaysAuthorization() |
| | | manan.distanceFilter = 15 |
| | | manan.distanceFilter = 10 |
| | | manan.allowsBackgroundLocationUpdates = true |
| | | manan.pausesLocationUpdatesAutomatically = false |
| | | manan.desiredAccuracy = kCLLocationAccuracyBestForNavigation |
| | | return manan |
| | | }() |
| | |
| | | sharpBtn.addTarget(self, action: #selector(sharpAction), for: .touchUpInside) |
| | | positionBtn.addTarget(self, action: #selector(locationToAction), for: .touchUpInside) |
| | | userLocalBtn.addTarget(self, action: #selector(currentUserLocation), for: .touchUpInside) |
| | | |
| | | mananger.startUpdatingLocation() |
| | | } |
| | | |
| | | override func setRx() { |
| | | NotificationCenter.default.rx.notification(UpdateMap_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in |
| | | guard let weakSelf = self else { return } |
| | | if let tuple = noti.object as? OrderDetailModel{ |
| | | |
| | | UserDefaults.standard.set(tuple.toJSONString(), forKey: "CurrentOrder") |
| | | UserDefaults.standard.synchronize() |
| | | |
| | | // switch tuple.data!.status{ |
| | | // case .PendingPickupDeparture,.ArrivedPort,.SendTOCheckPoint,.Checking,.PendingPickupInCheckPoint,.InTransitInYard,.InYard,.Transiting,.InWarehouse,.PendingUnload,.Unloaded,.TransitingToYard,.InYardByEmpty,.BackYard: |
| | | // default: |
| | | // weakSelf.mananger.stopUpdatingLocation() |
| | | // } |
| | | |
| | | var wayPointes = [String]() |
| | | for tu in tuple.lonlat{ |
| | |
| | | weakSelf.checkMarker.map = weakSelf.mapView |
| | | wayPointes.append(String(format: "via:%lf,%lf", weakSelf.checkMarker.position.latitude,weakSelf.checkMarker.position.longitude)) |
| | | case .StartPoint: |
| | | // weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: 30.670682, longitude: 104.078942) //测试 |
| | | weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lon) |
| | | weakSelf.startMarker.map = weakSelf.mapView |
| | | case .Terminal: |
| | | // weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: 30.616992, longitude: 104.070893) //测试 |
| | | weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lon) |
| | | weakSelf.destionMarker.map = weakSelf.mapView |
| | | case .Yard: |
| | |
| | | wayPointes.append(String(format: "via:%lf,%lf", weakSelf.yardMarker.position.latitude,weakSelf.yardMarker.position.longitude)) |
| | | } |
| | | } |
| | | |
| | | // 1 - 2: 2,3,5,12,13,14 |
| | | // 1- 3: 5,6 |
| | | // 3 - 4: 7,15 |
| | | //4 - 3: 9,10,11 |
| | | // 3 - 1: 11,18 |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | GoogleServices.directionsLine(origin: .byCoordinates(weakSelf.startMarker.position), destination: .byCoordinates(weakSelf.destionMarker.position), waypoints: wayPointes.joined(separator: "|")).subscribe(onNext: {[weak self] data in |
| | |
| | | }) { error in |
| | | |
| | | }.disposed(by: weakSelf.disposeBag) |
| | | self?.mananger.startUpdatingLocation() |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | |
| | | let alertVC = UIAlertController(title: "Navgation", message: "Where to go?", preferredStyle: .actionSheet) |
| | | |
| | | |
| | | if checkMarker.position.latitude != 0 && checkMarker.position.longitude != 0{ |
| | | if checkMarker.position.latitude != -180 && checkMarker.position.longitude != -180{ |
| | | alertVC.addAction(UIAlertAction(title: "Check Point", style: .default) { [weak self] _ in |
| | | guard let weakSelf = self else { return } |
| | | MapNavigationTool.startNav(weakSelf.checkMarker.position, distanceName: weakSelf.checkMarker.title ?? "None", scheme: "BrokerDriver") |
| | | }) |
| | | } |
| | | |
| | | if yardMarker.position.latitude != 0 && yardMarker.position.longitude != 0{ |
| | | if yardMarker.position.latitude != -180 && yardMarker.position.longitude != -180{ |
| | | alertVC.addAction(UIAlertAction(title: "Yard Point", style: .default) { [weak self] _ in |
| | | guard let weakSelf = self else { return } |
| | | MapNavigationTool.startNav(weakSelf.yardMarker.position, distanceName: weakSelf.yardMarker.title ?? "None", scheme: "BrokerDriver") |
| | | }) |
| | | } |
| | | |
| | | if destionMarker.position.latitude != -180 && destionMarker.position.longitude != -180{ |
| | | alertVC.addAction(UIAlertAction(title: "Terminal Point", style: .default) { [weak self] _ in |
| | | guard let weakSelf = self else { return } |
| | | MapNavigationTool.startNav(weakSelf.destionMarker.position, distanceName: weakSelf.destionMarker.title ?? "None", scheme: "BrokerDriver") |
| | | }) |
| | | } |
| | | |
| | | if startMarker.position.latitude != -180 && startMarker.position.longitude != -180{ |
| | | alertVC.addAction(UIAlertAction(title: "Start Point", style: .default) { [weak self] _ in |
| | | guard let weakSelf = self else { return } |
| | | MapNavigationTool.startNav(weakSelf.startMarker.position, distanceName: weakSelf.startMarker.title ?? "None", scheme: "BrokerDriver") |
| | | }) |
| | | } |
| | | |
| | |
| | | make.height.equalTo(24) |
| | | } |
| | | } |
| | | |
| | | func updateBounds(carCoordinate:CLLocationCoordinate2D?,terminalCoordinate:CLLocationCoordinate2D?){ |
| | | |
| | | |
| | | var centerCoordiante:CLLocationCoordinate2D? |
| | | |
| | | if carCoordinate != nil{ |
| | | carMarker.position = carCoordinate! |
| | | carMarker.map = mapView |
| | | centerCoordiante = carCoordinate |
| | | } |
| | | |
| | | if terminalCoordinate != nil{ |
| | | destionMarker.position = terminalCoordinate! |
| | | destionMarker.map = mapView |
| | | centerCoordiante = terminalCoordinate |
| | | } |
| | | |
| | | if carCoordinate != nil && terminalCoordinate != nil{ |
| | | let bounds = GMSCoordinateBounds(coordinate: carCoordinate!, coordinate: terminalCoordinate!) |
| | | let update = GMSCameraUpdate.fit(bounds, with: UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30)) |
| | | mapView.moveCamera(update) |
| | | updatePath(start: carCoordinate!, terminal: terminalCoordinate!) |
| | | }else if centerCoordiante != nil{ |
| | | mapView.animate(toLocation: centerCoordiante!) |
| | | } |
| | | } |
| | | |
| | | private func updatePath(start:CLLocationCoordinate2D,terminal:CLLocationCoordinate2D){ |
| | | |
| | | let path = GMSMutablePath() |
| | | path.add(start) |
| | | path.add(terminal) |
| | | |
| | | polyline.path = path |
| | | polyline.map = mapView |
| | | } |
| | | |
| | | |
| | | private func addPathInMap(snaps:[SnappedPointModel]){ |
| | | let path = GMSMutablePath() |