由于我使用Xcode 6.2开发了这个应用程序,我发现了一些问题,很多都解决了,但是这一个,可能需要重新构建我的应用程序。 在下面的代码中, filterByProximity 函数会出错。 我支持是一个选项问题(Nils Ziehn警告我here关于它的问题)。另一位开发人员告诉我:“使用缓存下载位置对象,然后进行查询”。
嗯,有可能吗?我该怎么做?在这里我的代码:
import UIKit
import MapKit
import CoreLocation
class MapViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
var locationManager = CLLocationManager()
var lat = locationManager.location.coordinate.latitude
var lon = locationManager.location.coordinate.longitude
let location = CLLocationCoordinate2D(latitude: lat, longitude: lon)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegionMake(location, span)
mapView.setRegion(region, animated: true)
let anotation = MKPointAnnotation()
anotation.setCoordinate(location)
anotation.title = "my title"
anotation.subtitle = " my subtitle"
mapView.addAnnotation(anotation)
println("****** Welcome in MapViewController")
//MARK: (471) Crossing Positions
//*******************************************************
let myGeoPoint = PFGeoPoint(latitude: lat, longitude:lon)
let myParseId = PFUser.currentUser().objectId //PFUser.currentUser().objectId
println("****** this is my geoPoint from map view controller: \(myGeoPoint)")
//
// var inspector = PFQuery(className:"GameScore")
// inspector.saveInBackgroundWithBlock {
// (success: Bool, error: NSError?) -> Void in
// if (success) {
// // The object has been saved.
// var the = inspector.objectId
// } else {
// // There was a problem, check error.description
// }
// }
//
//
//
//MARK: *** let's look for other users ***
// func filterByProximity() {
// PFQuery(className: "Position")
// .whereKey("where", nearGeoPoint: myGeoPoint, withinKilometers: 500.0) //(474)
// .findObjectsInBackgroundWithBlock ({
// objects, error in
// if let proximityArray = objects as? [PFObject] {
// println("****** here the proximity matches: \(proximityArray)")
// for near in proximityArray {
// println("here they are \(near)")
//
// let position = near["where"] as? PFGeoPoint
//
//// if let position = near["where"] as! PFGeoPoint {
//// let theirLat = position.latitude
//// let theirLon = position.longitude
//// }
//
// let theirLat = near["where"].latitude as Double
// let theirlong = near["where"].longitude as Double
// let location = CLLocationCoordinate2DMake(theirLat, theirlong)
// let span = MKCoordinateSpanMake(0.05, 0.05)
// let region = MKCoordinateRegionMake(location, span)
// self.mapView.setRegion(region, animated: true)
// let theirAnotation = MKPointAnnotation()
// theirAnotation.setCoordinate(location)
// self.mapView.addAnnotation(anotation)
//
//
// }
// }
// })
// }
//
// filterByProximity()
// //MARK: *** let's update my position (on Parse) ***
//
// func exists() {
// PFQuery(className:"Position")
// .whereKey("who", containsString: myParseId)
// .findObjectsInBackgroundWithBlock({
// thisObject, error in
// if let result = thisObject as? [PFObject] {
// println("here the result: \(result)")
//
// let gotTheId = result[0].objectId
// println("ecco l'id singolo \(gotTheId)")
//
// //******** update function ********
// var query = PFQuery(className:"Position")
// query.getObjectInBackgroundWithId(gotTheId) {
// (usingObject: PFObject?, error: NSError?) -> Void in
// if error != nil {
// println(error)
// } else if let objectToupdate = usingObject {
// println("else occurred")
// objectToupdate["where"] = myGeoPoint
// println("position should be updated")
// objectToupdate.saveInBackgroundWithBlock(nil)
// println("position should be saved")
//
// }
// }
// //******** end update function ********
// }
// })
// }
//
// exists()
//*******************************************************
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}