2014-09-19 99 views
-2

我成功了,已經找回了用戶的位置,並且我還設法找回了所有餐廳的位置(GeoPoint un data cloud Parse)我的問題是現在要知道如何比較位置與餐廳的用戶有距離的公里?位置解析幫助請

我覺得這是在文檔解析

- (void)whereKey:(NSString *)key nearGeoPoint: (PFGeoPoint *)geopoint withinKilometers: (double)maxDistance 

但在那裏我可以插入呢?

+0

應該遷移到StackOverflow – 2014-09-19 13:33:51

回答

0

Wherekey:nearGeoPoint:withInKilometers方法主要用於在用戶當前位置周圍搜索具有圓範圍的模型(餐廳,酒店等)。
你必須得到用戶的位置和餐廳之間的差異。爲此,你必須比較兩個位置的經緯度。

不同之處在於程度。

  • 1度表示apx。 11英里
  • 1英里的意思是apx。 1.76公里。
0

如果haven't已經做到了,這是一個偉大的教程你可以看看到:

https://parse.com/tutorials/anywall

,我認爲你正在尋找的代碼是這樣的。

[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *currentLocationGeoPoint, NSError *error) { //Get current Location 
    if (!error) {    
PFGeoPoint *distanceGeoPoint = [object objectForKey:@"location"]; 

     double distanceDouble = [currentLocationGeoPoint distanceInKilometersTo:distanceGeoPoint]; 
     NSLog(@"Distance: %.1f",distanceDouble) 

} 
}];