Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用纬度和经度在ARKit中绘制多段线?_Ios_Swift_Mapkit_Augmented Reality_Arkit - Fatal编程技术网

Ios 如何使用纬度和经度在ARKit中绘制多段线?

Ios 如何使用纬度和经度在ARKit中绘制多段线?,ios,swift,mapkit,augmented-reality,arkit,Ios,Swift,Mapkit,Augmented Reality,Arkit,目前,我可以在ARKit地理定位跟踪中使用纬度和经度渲染球体,是否有人可以指导我如何在ARKit中的2个CLLocation之间绘制多段线。以下是在两点之间创建多段线的完整代码,还可以设置该多段线的宽度和颜色 var locManager = CLLocationManager() var currentLocation: CLLocation! let annotation = MKPointAnnotation() let annotation2 = MKPointAnnotation()

目前,我可以在ARKit地理定位跟踪中使用纬度和经度渲染球体,是否有人可以指导我如何在ARKit中的2个CLLocation之间绘制多段线。

以下是在两点之间创建多段线的完整代码,还可以设置该多段线的宽度和颜色

var locManager = CLLocationManager()
var currentLocation: CLLocation!

let annotation = MKPointAnnotation()
let annotation2 = MKPointAnnotation()

// MARK:- DRIVER -
var driverLatitute:String!
var driverLongitude:String!

// MARK:- RESTAURANT -
var restaurantLatitude:String!
var restaurantLongitude:String!
鉴于此,我没有加载

// MARK:- 1 ( MAP ) -
        self.locManager.requestWhenInUseAuthorization()
        if CLLocationManager.locationServicesEnabled() {
            self.locManager.delegate = self
            self.locManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
            self.locManager.startUpdatingLocation()
            print("UPDATE UPDATE")
        }
       
        if (CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse ||
            CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways) {
            print("")
        }
委托方法

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
              
        
                            //print("**********************")
                            //print("Long \(manager.location!.coordinate.longitude)")
                            //print("Lati \(manager.location!.coordinate.latitude)")
                            //print("Alt \(manager.location!.altitude)")
                            //print("Speed \(manager.location!.speed)")
                            //print("Accu \(manager.location!.horizontalAccuracy)")
                            //print("**********************")
                
                //print(Double((vendorLatitute as NSString).doubleValue))
                //print(Double((vendorLongitute as NSString).doubleValue))
                
        /*
         // restaurant
         self.restaurantLatitude     = (dict["deliveryLat"] as! String)
         self.restaurantLongitude    = (dict["deliveryLong"] as! String)
           
         // driver
         self.driverLatitute     = (dict["resturentLatitude"] as! String)
         self.driverLongitude    = (dict["resturentLongitude"] as! String)
         */
        
        let restaurantLatitudeDouble    = Double(self.restaurantLatitude)
        let restaurantLongitudeDouble   = Double(self.restaurantLongitude)
        let driverLatitudeDouble        = Double("\(manager.location!.coordinate.latitude)") //Double(self.driverLatitute)
        let driverLongitudeDouble       = Double("\(manager.location!.coordinate.longitude)") // Double(self.driverLongitude)
        
        let coordinate₀ = CLLocation(latitude: restaurantLatitudeDouble!, longitude: restaurantLongitudeDouble!)
            let coordinate₁ = CLLocation(latitude: driverLatitudeDouble!, longitude: driverLongitudeDouble!)
        
    /************************************** RESTAURANT LATITUTDE AND LONGITUDE  ********************************/
                        // first location
        let sourceLocation = CLLocationCoordinate2D(latitude: restaurantLatitudeDouble!, longitude: restaurantLongitudeDouble!)
    /********************************************************************************************************************/
                                            

    /************************************* DRIVER LATITUTDE AND LINGITUDE ******************************************/
                        // second location
                        let destinationLocation = CLLocationCoordinate2D(latitude: driverLatitudeDouble!, longitude: driverLongitudeDouble!)
    /********************************************************************************************************************/
          
                //print(sourceLocation)
                //print(destinationLocation)
                 
                        let sourcePin = customPin(pinTitle: "You", pinSubTitle: "", location: sourceLocation)
                        let destinationPin = customPin(pinTitle: "Driver", pinSubTitle: "", location: destinationLocation)

    /***************** REMOVE PREVIUOS ANNOTATION TO GENERATE NEW ANNOTATION *******************************************/
                    self.mapView.removeAnnotations(self.mapView.annotations)
    /********************************************************************************************************************/
                
        self.mapView.addAnnotation(sourcePin)
        self.mapView.addAnnotation(destinationPin)
                       
        let sourcePlaceMark = MKPlacemark(coordinate: sourceLocation)
        let destinationPlaceMark = MKPlacemark(coordinate: destinationLocation)
                                                   
        let directionRequest = MKDirections.Request()
        directionRequest.source = MKMapItem(placemark: sourcePlaceMark)
        directionRequest.destination = MKMapItem(placemark: destinationPlaceMark)
        directionRequest.transportType = .automobile
                               
        let directions = MKDirections(request: directionRequest)
        directions.calculate { [self] (response, error) in
            guard let directionResonse = response else {
                if let error = error {
                    print("we have error getting directions==\(error.localizedDescription)")
                }
                return
            }
                                   
    /***************** REMOVE PREVIUOS POLYLINE TO GENERATE NEW POLYLINE *******************************/
            let overlays = self.mapView.overlays
            self.mapView.removeOverlays(overlays)
    /************************************************************************************/
    
                                
    /***************** GET DISTANCE BETWEEN TWO CORDINATES *******************************/
                             
                                let distanceInMeters = coordinate₀.distance(from: coordinate₁)
                                // print(distanceInMeters as Any)
                                
                                // remove decimal
                                let distanceFloat: Double = (distanceInMeters as Any as! Double)
                                // print(distanceFloat as Any)
                                // self.lblDistance.text = (String(format: "Distance : %.0f Miles away", distanceFloat/1609.344))
                                self.lblTotalDistance.text = (String(format: "Distance : %.0f Miles away", distanceFloat/1609.344))
                                
                                // print(distanceFloat/1609.344)
                                // print(String(format: "Distance : %.0f Miles away", distanceFloat/1609.344))
                                
                                
                                let s:String = String(format: "%.0f",distanceFloat/1609.344)
                                // print(s as Any)
                               
                                 
                                  
                                
                                
                                
                                
                                
    /************************************************************************************/
                                
    /***************** GENERATE NEW POLYLINE *******************************/
                                let route = directionResonse.routes[0]
                                self.mapView.addOverlay(route.polyline, level: .aboveRoads)
                                let rect = route.polyline.boundingMapRect
                                self.mapView.setRegion(MKCoordinateRegion(rect), animated: true)
    /************************************************************************************/
                           
                               }
        self.mapView.delegate = self
        print("update location after 5 sec")
        
        
        
                        // self.locManager.stopUpdatingLocation()
                
                // speed = distance / time
    }



    // line width of poly line
    //MARK:- MapKit delegates -
        func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
            let renderer = MKPolylineRenderer(overlay: overlay)
            renderer.strokeColor = UIColor.blue
            renderer.lineWidth = 4.0
            return renderer
        }

谢谢你的回复,但我已经用ARKIT写了,意思是在增强现实中