在Swift中使用未解析的标识符“MapTasks”

时间:2016-07-20 21:07:48

标签: objective-c swift xcode google-maps google-maps-sdk-ios

我正在关注tutorial,因为它是非常古老的教程,他们实际上使用了GoogleMaps框架包而不是我遵循的pods,一切都很顺利,直到我到达发现自定义位置 。在该部分中,他们要求更新func geocodeAddress,如下所示,并在我执行的ViewController.swift文件中添加var mapTasks = MapTasks(),但它给了我错误。

  

使用未解析的标识符'MapTasks'

error

func geocodeAddress(address: String!, withCompletionHandler completionHandler: ((status: String, success: Bool) -> Void)) {
    if let lookupAddress = address {
        var geocodeURLString = baseURLGeocode + "address=" + lookupAddress
        geocodeURLString = geocodeURLString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!

        let geocodeURL = NSURL(string: geocodeURLString)

        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            let geocodingResultsData = NSData(contentsOfURL: geocodeURL!)

            var error: NSError?
            let dictionary: Dictionary<NSObject, AnyObject> = NSJSONSerialization.JSONObjectWithData(geocodingResultsData!, options: NSJSONReadingOptions.MutableContainers, error: &error) as Dictionary<NSObject, AnyObject>

            if (error != nil) {
                println(error)
                completionHandler(status: "", success: false)
            }
            else {
                // Get the response status.
                let status = dictionary["status"] as String

                if status == "OK" {
                    let allResults = dictionary["results"] as Array<Dictionary<NSObject, AnyObject>>
                    self.lookupAddressResults = allResults[0]

                    // Keep the most important values.
                    self.fetchedFormattedAddress = self.lookupAddressResults["formatted_address"] as String
                    let geometry = self.lookupAddressResults["geometry"] as Dictionary<NSObject, AnyObject>
                    self.fetchedAddressLongitude = ((geometry["location"] as Dictionary<NSObject, AnyObject>)["lng"] as NSNumber).doubleValue
                    self.fetchedAddressLatitude = ((geometry["location"] as Dictionary<NSObject, AnyObject>)["lat"] as NSNumber).doubleValue

                    completionHandler(status: status, success: true)
                }
                else {
                    completionHandler(status: status, success: false)
                }
            }
        })
    }
    else {
        completionHandler(status: "No valid address.", success: false)
    }
}

这是我的GitHub repository

提前谢谢你。

1 个答案:

答案 0 :(得分:2)

如果你完全阅读了该教程,你会在指令中找到你需要创建一个文件名MapTasks这是一个类。 您只需从GitHub复制此file并将其添加到您的项目中即可。