currLocation和其他重定位函数的未解析标识符

时间:2015-10-05 13:34:03

标签: swift parse-platform core-location

我正在开发一款试图获取用户位置并在查询中查看内容的应用。我已经在框架中添加了corelocation并将其导入到viewcontroller中,但是我收到一条错误说" currLocation"是一个未解决的标识符和"位置管理器"在queryfortable函数和位置管理器函数下是不明确的。我该如何解决这个错误?

import UIKit
import CoreLocation
import Parse


@available(iOS 8.0, *)

class TableViewController: UITableViewController,CLLocationManagerDelegate {

    let bubbleFeeds = [
        ("1"),
        ("2"),
        ("I3"),
        ("4"),
        ("5"),
        ("6") ]


    let locationManager = CLLocationManager()
    var currLocation : CLLocationCoordinate2D?


    private func alert(message : String) {
        let alert = UIAlertController(title: "Oops something went wrong.", message: message, preferredStyle: UIAlertControllerStyle.Alert)
        let action = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)
        let cancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil)
        let settings = UIAlertAction(title: "Settings", style: UIAlertActionStyle.Default) { (action) -> Void in
            UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
            return
        }
        alert.addAction(settings)
        alert.addAction(action)
        self.presentViewController(alert, animated: true, completion: nil)
    }


    var resultsNameArray = [String]()
    var resultsImageFiles = [PFFile]()
    var resultsBubbleArray = [String]()



    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return resultsNameArray.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {


        let cell = tableView.dequeueReusableCellWithIdentifier("BubbleCell", forIndexPath: indexPath) as! Bubbles
        let BubbleCell = PFObject(className: "BubbleTest")

        cell.name.text = PFUser.valueForKey("userName") as! String
        cell.message.text = PFObject.valueForKey("textField") as! String
        cell.dateTime.text = "\((indexPath.row + 1) * 3)m ago"
        cell.message.numberOfLines = 0
        let score = PFObject.valueForKey("count") as! Int
        cell.LikeCounter.text = "\(score)"
        let replycnt = PFObject.valueForKey("replies") as! Int
        cell.responseCounter.text = "\(replycnt) replies"
        cell.img.image = PFUser.currentUser()?.valueForKey("photo") as! PFFile

        return cell


    }

    override func viewDidLoad() {

        super.viewDidLoad()

        locationManager.desiredAccuracy = 1000
        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()
        _ = currLocation

    }

    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
        ("Cannot fetch your location")
    }
}

在代码的这些部分中,我遇到了" currLocation"和#34; locationManager"暧昧。

func queryForTable() -> PFQuery! {
    let query = PFQuery(className: "BubbleTest")
    if let queryLoc = currLocation {
        query.whereKey("location", nearGeoPoint: PFGeoPoint(latitude: queryLoc.latitude, longitude: queryLoc.longitude), withinMiles: 10)
        query.limit = 200;
        query.orderByDescending("createdAt")
    } else {
        /* Decide on how the application should react if there is no location available */
        query.whereKey("location", nearGeoPoint: PFGeoPoint(latitude: 37.411822, longitude: -121.941125), withinMiles: 10)
        query.limit = 200;
        query.orderByDescending("createdAt")
    }

    return query
}


func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    locationManager.stopUpdatingLocation()
    if(locations.count > 0){
        let location = locations[0]
        print(location.coordinate)
        currLocation = location.coordinate
    } else {
        alert("Cannot receive your location")
    }
}

过去两天我一直试图解决这个问题,这让我疯狂。如果有人可以请求帮助,我会非常感激。

0 个答案:

没有答案