| | |
| | | private lazy var mapView:GMSMapView = { |
| | | let map = GMSMapView() |
| | | map.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: JQ_ScreenW * 0.6) |
| | | map.mapType = .normal |
| | | map.settings.scrollGestures = false |
| | | map.settings.zoomGestures = false |
| | | map.accessibilityElementsHidden = false |
| | | map.isBuildingsEnabled = false |
| | | map.isMyLocationEnabled = false |
| | | map.settings.scrollGestures = true |
| | | map.settings.zoomGestures = true |
| | | map.isBuildingsEnabled = true |
| | | map.settings.compassButton = true |
| | | map.settings.myLocationButton = false |
| | | map.setMinZoom(15, maxZoom: 20) |
| | | map.delegate = self |
| | | return map |
| | | }() |
| | | |
| | | private lazy var mananger:CLLocationManager = { |
| | | let manan = CLLocationManager() |
| | | manan.delegate = self |
| | | manan.requestAlwaysAuthorization() |
| | | manan.distanceFilter = 15 |
| | | manan.desiredAccuracy = kCLLocationAccuracyBestForNavigation |
| | | return manan |
| | | }() |
| | | |
| | | private lazy var destionMarker:GMSMarker = { |
| | | let marker = GMSMarker() |
| | |
| | | return marker |
| | | }() |
| | | |
| | | private lazy var startMarker:GMSMarker = { |
| | | let marker = GMSMarker() |
| | | marker.title = "Start" |
| | | marker.icon = UIImage(named: "maker_start") |
| | | return marker |
| | | }() |
| | | |
| | | private lazy var carMarker:GMSMarker = { |
| | | let marker = GMSMarker() |
| | | marker.title = "Car" |
| | | marker.icon = UIImage(named: "marker_car") |
| | | return marker |
| | | }() |
| | | |
| | | private lazy var checkMarker:GMSMarker = { |
| | | let marker = GMSMarker() |
| | | marker.title = "Check" |
| | | marker.icon = UIImage(named: "marker_check") |
| | | return marker |
| | | }() |
| | | |
| | | private lazy var yardMarker:GMSMarker = { |
| | | let marker = GMSMarker() |
| | | marker.title = "Warehouse" |
| | | marker.icon = UIImage(named: "marker_warehouse") |
| | | return marker |
| | | }() |
| | | |
| | | private lazy var polyline:GMSPolyline = { |
| | | let line = GMSPolyline() |
| | |
| | | |
| | | override func setRx() { |
| | | NotificationCenter.default.rx.notification(UpdateMap_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in |
| | | if let tuple = noti.object as? (CLLocationCoordinate2D?,CLLocationCoordinate2D?){ |
| | | self?.updateBounds(carCoordinate: tuple.0, terminalCoordinate: tuple.1) |
| | | guard let weakSelf = self else { return } |
| | | if let tuple = noti.object as? OrderDetailModel{ |
| | | |
| | | guard let start = tuple.lonlat.first else { return } |
| | | guard let terminal = tuple.lonlat.last else { return } |
| | | var wayPointes = [String]() |
| | | weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: 30.670682, longitude: 104.078942) |
| | | // weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: start.lat, longitude: start.lat) |
| | | weakSelf.startMarker.map = weakSelf.mapView |
| | | |
| | | |
| | | weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: 30.616992, longitude: 104.070893) |
| | | // weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: terminal.lat, longitude: terminal.lat) |
| | | weakSelf.destionMarker.map = weakSelf.mapView |
| | | |
| | | |
| | | |
| | | // 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 |
| | | |
| | | |
| | | // index = 3 // 1:起点,2:检查站 ,3:场地,4:终点 |
| | | // if tuple.lonlat.count == 4{ |
| | | // weakSelf.yardMarker.position = CLLocationCoordinate2D(latitude: tuple.lonlat[2].lat, longitude: tuple.lonlat[2].lon) |
| | | // weakSelf.yardMarker.map = weakSelf.mapView |
| | | // wayPointes.append(String(format: "%lf;%lf", weakSelf.yardMarker.position.latitude,weakSelf.yardMarker.position.longitude)) |
| | | // |
| | | // weakSelf.checkMarker.position = CLLocationCoordinate2D(latitude: tuple.lonlat[1].lat, longitude: tuple.lonlat[1].lon) |
| | | // weakSelf.checkMarker.map = weakSelf.mapView |
| | | // wayPointes.append(String(format: "%lf;%lf", weakSelf.checkMarker.position.latitude,weakSelf.checkMarker.position.longitude)) |
| | | // } |
| | | // |
| | | // if tuple.lonlat.count == 3{ |
| | | // weakSelf.checkMarker.position = CLLocationCoordinate2D(latitude: tuple.lonlat[1].lat, longitude: tuple.lonlat[1].lon) |
| | | // weakSelf.checkMarker.map = weakSelf.mapView |
| | | // wayPointes.append(String(format: "%lf;%lf", weakSelf.checkMarker.position.latitude,weakSelf.checkMarker.position.longitude)) |
| | | // } |
| | | |
| | | GoogleServices.directionsLine(origin: .byCoordinates(weakSelf.startMarker.position), destination: .byCoordinates(weakSelf.destionMarker.position), waypoints: wayPointes.joined(separator: "|")).subscribe(onNext: {[weak self] data in |
| | | if let lg = data.routes.first?.legs.first{ |
| | | self?.addPathInMap(leg: lg) |
| | | } |
| | | }) { error in |
| | | |
| | | }.disposed(by: weakSelf.disposeBag) |
| | | self?.mananger.startUpdatingLocation() |
| | | // self?.updateBounds(carCoordinate: tuple.0, terminalCoordinate: tuple.1) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | |
| | | |
| | | func updateBounds(carCoordinate:CLLocationCoordinate2D?,terminalCoordinate:CLLocationCoordinate2D?){ |
| | | |
| | | |
| | | var centerCoordiante:CLLocationCoordinate2D? |
| | | |
| | | if carCoordinate != nil{ |
| | |
| | | polyline.map = mapView |
| | | } |
| | | |
| | | |
| | | private func addPathInMap(snaps:[SnappedPointModel]){ |
| | | let path = GMSMutablePath() |
| | | for snap in snaps { |
| | | if snap.location?.latitude != nil && snap.location?.longitude != nil{ |
| | | let coordinate = CLLocationCoordinate2D(latitude: snap.location!.latitude!, longitude: snap.location!.longitude!) |
| | | path.add(coordinate) |
| | | } |
| | | } |
| | | let polyline = GMSPolyline(path: path) |
| | | polyline.strokeWidth = 6.0 |
| | | polyline.strokeColor = Def_ThemeColor |
| | | polyline.geodesic = true |
| | | polyline.map = mapView |
| | | self.polyline = polyline |
| | | } |
| | | |
| | | private func addPathInMap(leg:GoogleRoteRouteLegModel){ |
| | | let path = GMSMutablePath() |
| | | for step in leg.steps{ |
| | | let startLocation = CLLocationCoordinate2D(latitude: step.start_location!.lat, longitude: step.start_location!.lng) |
| | | let endLocation = CLLocationCoordinate2D(latitude: step.end_location!.lat, longitude: step.end_location!.lng) |
| | | path.add(startLocation) |
| | | path.add(endLocation) |
| | | } |
| | | |
| | | let polyline = GMSPolyline(path: path) |
| | | polyline.strokeWidth = 6.0 |
| | | polyline.strokeColor = Def_ThemeColor |
| | | polyline.geodesic = true |
| | | polyline.map = mapView |
| | | self.polyline = polyline |
| | | } |
| | | |
| | | @objc func troubleAction(){ |
| | | let vc = TroubleListVC(orderId: orderId) |
| | | push(vc: vc) |
| | | } |
| | | } |
| | | |
| | | extension HomeDetailMapVC:GMSMapViewDelegate{ |
| | | func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool { |
| | | JQ_MapNavigationTool.startNav(marker.position, distanceName: marker.title ?? "None", scheme: "BrokerDriver") |
| | | return true |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | extension HomeDetailMapVC:CLLocationManagerDelegate{ |
| | | func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { |
| | | if let location = locations.last{ |
| | | let marker = GMSMarker(position: location.coordinate) |
| | | marker.icon = UIImage(named: "marker_car") |
| | | marker.map = mapView |
| | | mapView.animate(toLocation: location.coordinate) |
| | | } |
| | | } |
| | | } |