-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathULGeoObject.m
49 lines (39 loc) · 1.25 KB
/
ULGeoObject.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// GeoObject.m
// Fuge
//
// Created by Mikhail Larionov on 8/4/13.
//
//
#import "ULGeoObject.h"
#import "ULLocationManager.h"
@implementation ULGeoObject
@synthesize strId = _strId, location = _location;
- (NSNumber*)distance
{
// Distance calculation
PFGeoPoint* geoPointUser = [locManager getPosition];
if ( ! self.location || ! geoPointUser )
return nil;
return [NSNumber numberWithDouble:
[geoPointUser distanceInKilometersTo:self.location]*1000.0f];
}
-(NSString*)distanceString:(Boolean)precise
{
NSNumber* distance = [self distance];
if ( ! distance )
return @"";
if ( [distance floatValue] < 100.0f ) {
if ( precise )
return [[NSString alloc] initWithFormat:@"%.0f m", [distance floatValue]];
else
return NSLocalizedString(@"USER_PROFILE_NEARBY",nil);
}
else if ( [distance floatValue] < 1000.0f )
return [[NSString alloc] initWithFormat:@"%.0f m", [distance floatValue]];
else if ( [distance floatValue] < 10000.0f )
return [[NSString alloc] initWithFormat:@"%.1f km", [distance floatValue]/1000.0f];
else
return [[NSString alloc] initWithFormat:@"%.0f km", [distance floatValue]/1000.0f];
}
@end