上传MapKit地区的火力点

问题描述 投票:0回答:1

我试图保存与用户位置后的地图,但我得到的值类型'的MKMapView?没有任何成员“的MKMapView”作为错误所有的时间...下面显示我的代码,但我离开了任何后台代码的图像和标签为那里的一切工作正常,我只是将它们包含在这里让你知道我是怎么救岗位信息......你知道我的错误是什么,我该怎么解决呢?

var takenMap: MKMapView!

@IBAction func postPressed(_ sender: Any) {
    if textView.text != "" && takenImage != nil && userLocation.text != "" {
        // Create and save a new job
        let newJob = Job(text: textView.text, jobImage: takenImage!, addedByUser: (userLabel?.text)!, userImage: UserImage, location: userLocation.text, map: takenMap.MKMapView)
        newJob.save()
}

//MARK:- CLLocationManager Delegates
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    if let lastLocation = locations.last {
        let geoCoder = CLGeocoder()

        let center = CLLocationCoordinate2D(latitude: lastLocation.coordinate.latitude, longitude: lastLocation.coordinate.longitude)
        let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
        map.setRegion(region, animated: true)
        self.map = takenMap

        geoCoder.reverseGeocodeLocation(lastLocation) { (placeMarks, error) in
            if error == nil {
                if let firstLocation = placeMarks?[0] {
                    self.locationManager.stopUpdatingLocation()

                    if let cityName = firstLocation.locality,
                        let street = firstLocation.thoroughfare {

                        self.scanLocation = "\(street), \(cityName)"
                        print("This is the current city name", cityName)
                        print("this is the current street address", street)
                        self.takenLocation = self.scanLocation!
                        self.userLocation.text = self.takenLocation
                    }
                }
            }
        }
    }
}

Job.swift:

var map: String?

init(map: String? = nil) {
    self.map = map
    ref = Database.database().reference().child("jobs").childByAutoId()
}

init(snapshot: DataSnapshot){
    ref = snapshot.ref
    if let value = snapshot.value as? [String : Any] {
        map = value["location"] as? String
    }
}

func save() {
    let newPostKey = ref.key

    // save jobImage
    if let imageData = jobImage?.jpegData(compressionQuality: 0.5) {
        let storage = Storage.storage().reference().child("jobImages/\(newPostKey)")

        storage.putData(imageData).observe(.success, handler: { (snapshot) in
            self.downloadURL = snapshot.metadata?.downloadURL()?.absoluteString
            let postDictionary = [
                "map" : self.map!
                ] as [String : Any]
            self.ref.setValue(postDictionary)
        })
    }
}

我离开了任何代码,标签或任何出这样的片段将不会太长

ios swift firebase mapkit
1个回答
0
投票

该代码takenMap.MKMapView也许应该只是takenMap

© www.soinside.com 2019 - 2024. All rights reserved.