问题描述
我正在开发一个应用程序,我想问一个问题请
Hi i developp an application and I would want to ask a question plz
在我的数据云解析中,我有餐厅"类,我有三列:名称"类型字符串;imageFile"类型文件;description"类型数组和Location"类型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
然后您将创建一个使用当前位置的查询location 以查找靠近用户位置的点.
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
}
}
}
}
这篇关于用户周围的位置解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!