Search code examples
objective-cswiftxcodegoogle-mapsgoogle-maps-sdk-ios

Use of unresolved identifier 'MapTasks' in Swift


I am following tutorial, as it is pretty old tutorial and they actually used GoogleMaps framework package instead of pods which I followed and everything was going smooth till I reached Spotting a Custom Location. In that section they asked to update func geocodeAddress as below, and add var mapTasks = MapTasks() in ViewController.swift file which I did but it gives me error.

Use of unresolved identifier '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)
    }
}

Here is my GitHub repository

Thank you in advance.


Solution

  • If you fully read that tutorial, you will find in the instruction that you need to create a file name MapTasks which is a class. You can just copy this file from GitHub and add it to your project.