Skip to content

Instantly share code, notes, and snippets.

View emilepetrone's full-sized avatar
🏠
Working from home

Emile Petrone emilepetrone

🏠
Working from home
View GitHub Profile
// get Context for a point
SGContextQuery *query = [SGContextQuery queryWithPoint:[SGPoint pointWithLat:37.772445 lon:-122.405913]];
[client getContextForQuery:query
callback:[SGCallback callbackWithSuccessBlock:
^(id response) {
// you've got Context!
// to create an SGContext object...
SGContext *context = [SGContext contextWithDictionary:response];
// get all your layers
[client getLayersWithCursor:nil // for pagination
callback:[SGCallback callbackWithSuccessBlock:
^(id response) {
// you've got layers!
// To create an array of SGLayer objects...
NSArray *layers = [NSArray arrayWithSGCollection:SGCollectionTypeLayers];
} failureBlock:^(NSError *error) {
// handle failure
// get info about a specific layer
[client getLayer:@"com.simplegeo.example"
callback:[SGCallback callbackWithSuccessBlock:
^(id response) {
// you've got a layer!
// To create an SGLayer object...
SGLayer *layer = [SGLayer layerWithDictionary:response];
} failureBlock:^(NSError *error) {
// handle failure
// delete a layer
[client deleteLayer:@"com.simplegeo.example"
callback:[SGCallback callbackWithSuccessBlock:
^(id response) {
// deletion confirmed
} failureBlock:^(NSError *error) {
// deletion failed
}]];
// add or update a layer
SGLayer *layer = [SGLayer layerWithName:@"com.simplegeo.example"
title:@"Example Layer"
description:@"Created from SimpleGeo.framework"
callbackURLs:nil]]; // optional list of callback URLs
[client addOrUpdateLayer:layer
callback:[SGCallback callbackWithSuccessBlock:
^(id response) {
// get a specific record
[client getRecord:@"recordID"
inLayer:@"com.simplegeo.example"
callback:[SGCallback callbackWithSuccessBlock:
^(id response) {
// you've got a record!
// to create an SGStoredRecord object...
SGStoredRecord *record = [SGStoredRecord recordWithGeoJSON:response];
} failureBlock:^(NSError *error) {
// get a record's location history
[client getHistoryForRecord:@"recordID"
inLayer:@"com.simplegeo.example"
limit:nil // optional limit
cursor:nil // for pagination
callback:[SGCallback callbackWithSuccessBlock:
^(id response) {
// you've got location history!
// to create an array of SGPoint objects...
// find ten records in a given area
SGEnvelope *envelope = [SGEnvelope envelopeWithNorth:40.613952
west:-105.90271
south:39.078908
east:-103.513184];
SGStorageQuery *query = [SGStorageQuery queryWithEnvelope:envelope
layer:@"com.simplegeo.example"];
// find the ten nearest records, created within the past 24 hours, within two kilometers of an address
SGStorageQuery *query = [SGStorageQuery queryWithAddress:@"41 Decatur St, San Francisco, CA"
layer:@"com.simplegeo.example"];
[query setRadius:2.0];
[query setLimit:10];
[query setDateRangeFrom:[NSDate dateWithTimeIntervalSinceNow:-86400]
to:[NSDate date]];
// get records near a point
SGStorageQuery *query = [SGStorageQuery queryWithPoint:[SGPoint pointWithLat:37.772445 lon:-122.405913]
layer:@"com.simplegeo.example"];
[client getRecordsForQuery:query
callback:[SGCallback callbackWithSuccessBlock:
^(id response) {
// you've got records!
// to create an array of SGStoredRecord objects...