Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在Swift中将解析地质点转换为CLLocation_Ios_Xcode_Swift_Parse Platform - Fatal编程技术网

Ios 在Swift中将解析地质点转换为CLLocation

Ios 在Swift中将解析地质点转换为CLLocation,ios,xcode,swift,parse-platform,Ios,Xcode,Swift,Parse Platform,我在斯威夫特工作 在我的解析后端中,我有一个名为locations的键,它有许多地理点值,其中包括纬度和经度点。我想查询/获取所有这些点,并将它们放入一个数组中,这样我就可以将它们用作地图上的不同注释 我在查询位置时遇到问题,因此无法将其用作地图的位置 如果有人能帮我做这件事,我将不胜感激。您可以创建一个变量作为PFGeoPoint,您可以将parse中的数据放入该变量中: var descLocation: PFGeoPoint = PFGeoPoint() var innerP1 = NS

我在斯威夫特工作

在我的解析后端中,我有一个名为locations的键,它有许多地理点值,其中包括纬度和经度点。我想查询/获取所有这些点,并将它们放入一个数组中,这样我就可以将它们用作地图上的不同注释

我在查询位置时遇到问题,因此无法将其用作地图的位置


如果有人能帮我做这件事,我将不胜感激。

您可以创建一个变量作为PFGeoPoint,您可以将parse中的数据放入该变量中:

var descLocation: PFGeoPoint = PFGeoPoint()

var innerP1 = NSPredicate(format: "ObjectID = %@", objectID)
    var innerQ1:PFQuery = PFQuery(className: "Test", predicate: innerP1)

    var query = PFQuery.orQueryWithSubqueries([innerQ1])
    query.addAscendingOrder("createdAt")
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]!, error: NSError!) -> Void in

        if error == nil {
            for object in objects {
                descLocation = object["GeoPoint"] as PFGeoPoint
            }
        } else {
            println("Error")
        }

    }
在需要位置的课堂上,只需添加以下行:

    var latitude: CLLocationDegrees = descLocation.latitude
    var longtitude: CLLocationDegrees = descLocation.longitude

    var location: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: latitude, longitude: longtitude)
因此,您可以使用以下代码向地图添加注释:

    @IBOutlet var map: MKMapView!
    var annotation = MKPointAnnotation()
    annotation.title = "Test"
    annotation.coordinate = location
    map.addAnnotation(annotation)

您可以创建一个变量作为PFGeoPoint,并可以将parse中的数据放入该变量中:

var descLocation: PFGeoPoint = PFGeoPoint()

var innerP1 = NSPredicate(format: "ObjectID = %@", objectID)
    var innerQ1:PFQuery = PFQuery(className: "Test", predicate: innerP1)

    var query = PFQuery.orQueryWithSubqueries([innerQ1])
    query.addAscendingOrder("createdAt")
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]!, error: NSError!) -> Void in

        if error == nil {
            for object in objects {
                descLocation = object["GeoPoint"] as PFGeoPoint
            }
        } else {
            println("Error")
        }

    }
在需要位置的课堂上,只需添加以下行:

    var latitude: CLLocationDegrees = descLocation.latitude
    var longtitude: CLLocationDegrees = descLocation.longitude

    var location: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: latitude, longitude: longtitude)
因此,您可以使用以下代码向地图添加注释:

    @IBOutlet var map: MKMapView!
    var annotation = MKPointAnnotation()
    annotation.title = "Test"
    annotation.coordinate = location
    map.addAnnotation(annotation)

您使用什么代码来执行查询?你说的“我查询位置有困难”是什么意思?什么样的问题?我使用的代码是:var query=PFUser.query(),然后是query.whereKey。我不知道如何从parse中查询位置,然后将其转换为CLLocation,以便它们可以用作地图上的批注。您是否正在尝试查询和查找数据库中靠近某个位置的位置?是的,我正在尝试查询和查找与当前用户最近的位置,然后将它们作为批注放置在地图上。我知道如何从Parse查询用户。我知道如何在地图上放置注释。我只是在一起努力。如果有任何帮助,我将不胜感激。您使用什么代码来执行查询?你说的“我查询位置有困难”是什么意思?什么样的问题?我使用的代码是:var query=PFUser.query(),然后是query.whereKey。我不知道如何从parse中查询位置,然后将其转换为CLLocation,以便它们可以用作地图上的批注。您是否正在尝试查询和查找数据库中靠近某个位置的位置?是的,我正在尝试查询和查找与当前用户最近的位置,然后将它们作为批注放置在地图上。我知道如何从Parse查询用户。我知道如何在地图上放置注释。我只是在一起努力。任何帮助我都会非常感激。