本文介绍了解析用户周围的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我想问一个问题PLZ

Hi i developp an application and I would want to ask a question plz

在我的数据云Parse中,我有餐厅"类,我有三列:名称"类型字符串; "imageFile"类型文件; 描述"类型数组和位置"类型GeoPoint.

In my data cloud Parse , i have class " restaurants " i have three columns : " name " type string ; "imageFile" type file ; "description " type array and "Location" type GeoPoint.

我想知道使用哪种方法取回用户的当前GeoPoint?然后,我想知道如何比较用户的GeoPoint和餐馆的GeoPoint,以便最终在距离用户最近的TableView餐馆中发布(显示).

I would want to know which method to use to get back current GeoPoint of the user?Then I would want to know how to compare GeoPoint of users and those of the restaurants to post(show) finally in TableView restaurants the closest to the user in kilometers.

推荐答案

要获取用户的位置,可以使用以下函数:PFGeoPoint.geoPointForCurrentLocationInBackground然后您将创建一个查询,该查询使用当前位置来查找附近的点.用户的位置.

To get the user's position, you can use the following function: PFGeoPoint.geoPointForCurrentLocationInBackground you would then create a query that uses the current location to find points that are near the user's location.

Swift中的代码示例:

Code Example in Swift:

//Get the user's current location
PFGeoPoint.geoPointForCurrentLocationInBackground {
    (point:PFGeoPoint!, error:NSError!) -> Void in
    if error == nil {
        //Point contains the user's current point

        //Get a max of 100 of the restaurants that are within 5km,
        //ordered from nearest to furthest
        var query = PFQuery(className: "restaurants")
        query.limit = 100
        query.whereKey("location", nearGeoPoint: point, withinKilometers: 5.0)
        query.findObjectsInBackgroundWithBlock{
            (objects: [AnyObject]!, error: NSError!) -> Void in
            if (error == nil) {
                //objects contains the restaurants
            }
        }
    }
}

这篇关于解析用户周围的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 19:02