简体   繁体   English

reverseGeocodeLocation:“无法为类型为'(placemark:CLPlacemark)'的参数列表调用类型'CLPlacemark'的初始化程序”

[英]reverseGeocodeLocation: “Cannot invoke initializer for type 'CLPlacemark' with an argument list of type '(placemark: CLPlacemark)'”

I am stumped on how to initializer this placemark within my reverseGeocodeLocation attempt. 我对如何在reverseGeocodeLocation尝试中初始化此地标感到困惑。

First, I do not know if the reverseGeocodeLocation is initialized correctly. 首先,我不知道reverseGeocodeLocation是否正确初始化。 It was giving me some issues; 它给了我一些问题; but Xcode seems to be okay with it at this point. 但是Xcode在这一点上似乎还可以。

The real issue comes at line 55: placemark = CLPlacemark(placemark: placemarkArr[0] as! CLPlacemark) 真正的问题出在第55行:placemark = CLPlacemark(placemark:placemarkArr [0] as!CLPlacemark)

I receive the error: "Cannot invoke initializer for type 'CLPlacemark' with an argument list of type '(place mark: CLPlacemark)'" 我收到错误:“无法使用类型为“(地标:CLPlacemark)”的参数列表来为类型“ CLPlacemark”调用初始化程序”

I am using Xcode 7 Beta 4; 我正在使用Xcode 7 Beta 4; so I don't know if this could be the issue. 所以我不知道这可能是问题。 I have seen older examples on how to write this line of code, but they all appear to be earlier code editions. 我已经看到了有关如何编写此代码行的较旧的示例,但它们似乎都是较早的代码版本。

Thanks for any help or suggestions! 感谢您的帮助或建议! This one has been stumping me for a while. 这个人困扰了我一段时间。

import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate{

    var manager:CLLocationManager?

    @IBOutlet weak var latitude: UILabel!
    @IBOutlet weak var longitude: UILabel!
    @IBOutlet weak var altitude: UILabel!
    @IBOutlet weak var course: UILabel!
    @IBOutlet weak var speed: UILabel!
    @IBOutlet weak var address: UILabel!


    override func viewDidLoad() {
        super.viewDidLoad()

        manager = CLLocationManager()
        manager!.delegate = self
        manager!.desiredAccuracy - kCLLocationAccuracyBest
        manager!.requestWhenInUseAuthorization()
        manager!.startUpdatingLocation()

    }


    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        print(locations)
        let userLocation:CLLocation = locations[0]
        self.latitude.text = "\(userLocation.coordinate.latitude)"
        self.longitude.text = "\(userLocation.coordinate.longitude)"
        self.course.text = "\(userLocation.course)"
        self.speed.text = "\(userLocation.speed)"
        self.altitude.text = "\(userLocation.altitude)"

        let geocoder = CLGeocoder()

        geocoder.reverseGeocodeLocation(userLocation) { (placemarkArr, error) -> Void in

            var placemark:CLPlacemark!
            //let gp = userLocation

            if error == nil && placemarkArr!.count > 0 {
                print(userLocation)

                placemark = CLPlacemark(placemark: placemarkArr[0] as! CLPlacemark)

                var addressString: String = ""
                if placemark.ISOcountryCode == "TW" {
                    if placemark.country != nil {
                    addressString = placemark.country!
                    }
                    if placemark.subAdministrativeArea != nil {
                    addressString = addressString + placemark.subAdministrativeArea! + ", "
                    }
                    if placemark.postalCode != nil {
                        addressString = addressString + placemark.postalCode! + " "
                    }
                    if placemark.locality != nil {
                        addressString = addressString + placemark.locality!
                    }
                }
            }
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }




}

I am no longer having this issue. 我不再遇到这个问题。 My code may be slightly different than above, so I have pasted below the portion of my code initializing the reverseGeocodeLocation: 我的代码可能与上面的代码略有不同,因此我在代码的下面粘贴了以下内容,以初始化reverseGeocodeLocation:

import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate{

let locationManager = CLLocationManager()

var longitude: Double!
var latitude: Double!

var thoroughfare = "unknown"
var subLocality = "unknown"
var subAdministrativeArea = "unknown"
var postCode = "unknown"
var locality = "unknown"

override func viewDidLoad() {
    super.viewDidLoad()

    self.locationManager.requestAlwaysAuthorization()
    self.locationManager.requestWhenInUseAuthorization()

    if CLLocationManager.locationServicesEnabled() {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.startUpdatingLocation()
    }

}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    latitude = userLocation.coordinate.latitude
    longitude = userLocation.coordinate.longitude

    let userLocation:CLLocation = locations[0]

    CLGeocoder().reverseGeocodeLocation(userLocation) { (placemarks, error) -> Void in

        if(error == nil) {
            let loc = placemarks![0]

            self.thoroughfare = String!(loc.thoroughfare)
            self.subLocality = String!(loc.subLocality)
            self.subAdministrativeArea = String!(loc.subAdministrativeArea)
            self.postCode = String!(loc.postalCode)
            self.locality = String!(loc.locality)
    } else {
            //print(error)
        }
        print("thoroughfare: " + self.thoroughfare)
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift 2.0-无法下标'[CLPlacemark]类型的值?” - Swift 2.0 - Cannot Subscript a value of type '[CLPlacemark]?' 无法为类型为“”的参数列表调用类型为“”的初始化程序 - Cannot invoke initializer for type '' with an argument list of type '' 无法使用类型为((fileURLWithPath:NSURL))的参数列表来调用类型为'NSURL'的初始化程序 - Cannot invoke initializer for type 'NSURL' with an argument list of type '(fileURLWithPath: NSURL)' 无法使用类型的参数列表调用类型“UIUserNotificationSettings”的初始值设定项 - Cannot invoke initializer for type 'UIUserNotificationSettings' with an argument list of type 无法使用类型为((array:[NSData?]))的参数列表来调用类型为'NSSet'的初始化程序 - Cannot invoke initializer for type 'NSSet' with an argument list of type '(array: [NSData?])' 无法为类型调用初始值设定项:使用类型为'(_Element)'的参数列表 - Cannot invoke initializer for type: with an argument list of type '(_Element)' 无法为类型为'(UInt32)'的参数列表调用类型'CGBitmapInfo'的初始化程序 - Cannot invoke initializer for type 'CGBitmapInfo' with an argument list of type '(UInt32)' 更新到xcode 7后出现错误:无法使用类型为参数的列表调用类型为'NSRegularExpression'的初始化程序 - Error after updating to xcode 7 : Cannot invoke initializer for type 'NSRegularExpression' with an argument list of type 无法为类型为nsdictionary的类型的参数列表(对象:字符串?用于键[]字符串)调用初始化程序 - Cannot invoke initializer for type nsdictionary with an argument list of type(objects:String?for key [] string) 无法为类型为参数列表(字符串:字符串,属性:[NSObject:AnyObject]的NSAttributedString类型)调用初始化程序。 - Cannot invoke initializer for type NSAttributedString with an argument list of type (string: String, attributes: [NSObject: AnyObject]?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM