Skip to content

Instantly share code, notes, and snippets.

@funkyboy
Last active August 29, 2015 14:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funkyboy/5bc3d8edf9dea130fb3c to your computer and use it in GitHub Desktop.
Save funkyboy/5bc3d8edf9dea130fb3c to your computer and use it in GitHub Desktop.
BAAClient *c = [BAAClient sharedClient];
[c authenticateUser:@"aaa" password:@"aaa" completion:^(BOOL success, NSError *error) {
if (success) {
SMTest *test = [[SMTest alloc] init];
test.latitude = 45.2769564;
test.longitude = 10.879298;
[test saveObjectWithCompletion:^(SMTest *object, NSError *error) {
if (error == nil) {
NSLog(@"coordinates saved on server %f, %f", object.coordinate.latitude,object.coordinate.longitude);
}
}];
} else {
NSLog(@"err %@", error);
}
}];
NSDictionary *parameters = @{@"where" : @"distance (latitude,longitude,45.2769564,10.879298) <= 10"};
[SMTest getObjectsWithParams:parameters
completion:^(NSArray *places, NSError *error) {
if (error == nil) {
NSLog(@"Places are %@", places);
} else {
// deal with error
}
}];
#import "BAAObject.h"
#import <CoreLocation/CoreLocation.h>
@interface SMTest : BAAObject
@property (nonatomic, assign) NSInteger myInteger;
@property (nonatomic, assign) double latitude;
@property (nonatomic, assign) double longitude;
- (CLLocationCoordinate2D)coordinate;
@end
#import "SMTest.h"
@implementation SMTest
- (instancetype)initWithDictionary:(NSDictionary *)dictionary {
self = [super initWithDictionary:dictionary];
if (self) {
_myInteger = [dictionary[@"myInteger"] integerValue];
_latitude = [dictionary[@"latitude"] doubleValue];
_longitude = [dictionary[@"longitude"] doubleValue];
}
return self;
}
-(NSString *)collectionName {
return @"document/test";
}
- (CLLocationCoordinate2D) coordinate {
CLLocationCoordinate2D myCoordinate;
myCoordinate.latitude = _latitude;
myCoordinate.longitude = _longitude;
return myCoordinate;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment