App42 Cloud API

iOS cloud SDK

Geo

Geo Spatial Service on cloud provides the storage , retrieval , querying and updation of geo data. One can store the geo data by unique handler on the cloud and can apply search , update and query on it. Geo spatial query includes finding nearby/In circle target point from given point using geo points stored on the cloud.

In order to use the various functions available under a particular API, a developer will have to allocate and initialize an instance of ServiceAPI. After initialization, apiKey and secretKey needs to be set which has been received while creating an application under App42.

ServiceAPI *serviceAPIObj = [[ServiceAPI alloc]init];
serviceAPIObj.apiKey = @"<API_KEY>";
serviceAPIObj.secretKey = @"<SECRET_KEY>"; 

After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of GeoService, buildGeoService() method needs to be called.

	GeoService *geoService = [serviceAPIObj buildGeoService];

Once the API instance has been retrieved, You are ready to use the functions available for that particular API.

The methods available under a particular API will return the domain object (like Geo in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have provided the JSON response with every function detail which can be retrieved by calling the toString() on the returned object.

NSString *geoStorageName = @"geoTest";
NSMutableArray *geoList = [[NSMutableArray alloc]init];					
GeoPoint *gp = [[GeoPoint alloc]init];
gp.marker = @"Maplewood,NJ";
gp.latitude = -74.2713;
gp.longitude = 40.73137;
[geoList addObject:gp];

Geo *geo = [geoService createGeoPoints:geoStorageName geoPointsList:geoPointsList]; /* returns the Geo object. */
NSString *storageName = geo.storageName;
NSMutableArray *pointList =  geo.pointList;
for(GeoPoint *point in pointList)
{
	NSLog(@"lat is = %@",point.latitude);
	NSLog(@"long is = %@",point.longitude);
	NSLog(@"marker is = %@",point.marker);
} 
NSString *jsonResponse = [geo toString]; /* returns the response in JSON format. */ 
                            

The functions available under Geo Spatial API can throw some exceptions in abnormal conditions. Example of the same has been given below.

E.g. If App developer is trying to delete the storage that does not exist, the function will throw the App42Exception (as shown below) with message as "Not Found" and the appErrorCode as "2903" and the details as "No Geo Storage Exist with Name ${storageName}".

NSString *storageName = @"geoTest";
@try{
	Geo *geo = [geoService deleteStorage:storageName];
} @catch(App42Exception *ex) {
	int appErrorCode = ex.appErrorCode;
	int httpErrorCode = ex.httpErrorCode;
	if(appErrorCode == 2903)
	{
		// Handle here for Not Found (No Geo Storage exists with name '<storageName>'.)
	}
	else if(appErrorCode == 1401){
		// handle here for Client is not authorized
	}
	else if(appErrorCode == 1500){
		// handle here for Internal Server Error
	}
	NSString *jsonText = ex.reason; /* returns the Exception text in JSON format. (as shown below)*/	
}
                            
	{
	   "app42Fault": {
		   "httpErrorCode": 404,
		   "appErrorCode": 2903,
		   "message": "Not Found",
		   "details": "No Geo Storage Exist with Name Geo Storage 2"
	   }
	}							

Below are the HTTP Error Codes and their description, the function under the Geo Spatial API can throw.

/*
1400 - BAD REQUEST - The Request parameters are invalid
1401 - UNAUTHORIZED - Client is not authorized
1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again	
*/						

Below are the Application Error Codes and their description, the function under the Geo Spatial API can throw.

/*
2900 - NOT FOUND - No destination found using given parameter Lat : '<lat>'  Long : '<lng>' and Distance In KM '<distanceInKM>'.
2901 - NOT FOUND - No destination found using given parameter Lat : '<lat>'  Long : '<lng>' and Radius In KM '<radiusInKM>'.
2902 - NOT FOUND - No Geo Storage exists.
2903 - NOT FOUND - No Geo Storage exists with name '<storageName>'.
2904 - NOT FOUND - No Geo Points in the storage '<storageName>' exist.
2905 - NOT FOUND - No destination found using given parameter Lat : '<lat>'  Long : '<lng>'.
*/							

Various functions available under Geo Spatial API has been explained below.

-(Geo*)createGeoPoints:(NSString*)geoStorageName geoPointsList:(NSArray*)geoPointsList

Stores the geopoints with unique handler on the cloud. Geo point data contains lat, long and marker of the point.

Parameters:

geoStorageName - Unique handler for storage name
geoPointsList - List of Geo Points to be saved

Returns:

Geo object containing list of Geo Points that have been saved

Response: Geo Object

For more details click Exception
NSString *geoStorageName = @"geoTest";
NSMutableArray *geoList = [[NSMutableArray alloc]init];					
GeoPoint *gp = [[GeoPoint alloc]init];
gp.marker = @"Maplewood,NJ";
gp.latitude = -74.2713;
gp.longitude = 40.73137;
[geoList addObject:gp];

Geo *geo = [geoService createGeoPoints:geoStorageName geoPointsList:geoPointsList]; /* returns the Geo object. */
NSString *storageName = geo.storageName;
NSMutableArray *pointList =  geo.pointList;
for(GeoPoint *point in pointList)
{
	NSLog(@"lat is = %@",point.latitude);
	NSLog(@"long is = %@",point.longitude);
	NSLog(@"marker is = %@",point.marker);
} 
NSString *jsonResponse = [geo toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "geo": {
                "storage": {
                    "storageName": "geoTest",
                    "points": {
                        "point": [
                            {
                                "lat": -73.99171,
                                "lng": 40.73887,
                                "marker": "10gen Office"
                            },
                            {
                                "lat": -73.98814,
                                "lng": 40.741405,
                                "marker": "Flatiron Building"
                            },
                            {
                                "lat": -73.99781,
                                "lng": 40.73913,
                                "marker": "Players Club"
                            },
                            {
                                "lat": -73.99249,
                                "lng": 40.738674,
                                "marker": "City Bakery"
                            }
                        ]
                    }
                }
            }
        }
    }
}
-(Geo*)getNearByPointsByMaxDistance:(NSString*)storageName latitude:(NSDecimalNumber*)lat longitude:(NSDecimalNumber*)lng distanceInKM:(NSDecimalNumber*)distanceInKM

Search the near by point in given range(In KM) from specified source point. Points to be searched should already be stored on cloud using unique storage name handler.

Parameters:

storageName - Unique handler for storage name
lat - Latitude of source point
lng - Longitude of source point
distanceInKM - Range in KM

Returns:

Geo object containing the target points in ascending order of distance from source point.

Response: Geo Object

Exception:

The method throws the following exception with the error code.
/* 
2900 - NOT FOUND - No destination found using given parameter Lat : '<lat>'  Long : '<lng>' and Distance In KM '<distanceInKM>'.
2905 - NOT FOUND - No destination found using given parameter Lat : '<lat>'  Long : '<lng>'.
*/ 		         
For more details click Exception
NSString *storageName = @"geoTest";
double lat = -73.99171;
double lng = 40.738868;
double distanceInKM = 1;						

Geo *geo = [geoService getNearByPointsByMaxDistance:storageName latitude:lat longitude:lng distanceInKM:distanceInKM]; /* returns the Geo object. */
NSLog(@"geoStorageName is = %@",geo.storageName);
NSLog(@"sourceLat is = %@",geo.sourceLat);
NSLog(@"distanceInKM is = %@",geo.distanceInKM);
NSLog(@"sourceLng is = %@",geo.sourceLng);
NSMutableArray *pointList =  geo.pointList;
for(GeoPoint *point in pointList)
{
	NSLog(@"lat is = %@",point.latitude);
	NSLog(@"long is = %@",point.longitude);
	NSLog(@"marker is = %@",point.marker);
} 
NSString *jsonResponse = [geo toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "geo": {
                "storage": {
                    "storageName": "geoTest",
                    "sourceLat": -73.99171,
                    "sourceLng": 40.738868,
                    "distanceInKM": 1,
                    "points": {
                        "point": [
                            {
                                "lat": -73.99171,
                                "lng": 40.73887,
                                "marker": "10gen Office"
                            },
                            {
                                "lat": -73.99249,
                                "lng": 40.738674,
                                "marker": "City Bakery"
                            },
                            {
                                "lat": -73.98814,
                                "lng": 40.741405,
                                "marker": "Flatiron Building"
                            },
                            {
                                "lat": -73.99781,
                                "lng": 40.73913,
                                "marker": "Players Club"
                            }
                        ]
                    }
                }
            }
        }
    }
}
-(Geo*)getNearByPoint:(NSString*)storageName latitude:(NSDecimalNumber*)lat longitude:(NSDecimalNumber*)lng resultLimit:(int)resultLimit

Search the near by point from specified source point. Points to be searched should already be stored on cloud using unique storage name handler.

Parameters:

storageName - Unique handler for storage name
lat - Lattitude of source point
lng - Longitude of source point
resultLimit - Maximum number of results to be retrieved

Returns:

Geo object containing the target points in ascending order of distance from source point.

Response: Geo Object

Exception:

The method throws the following exception with the error code.
/* 
2905 - NOT FOUND - No destination found using given parameter Lat : '<lat>'  Long : '<lng>'.
*/ 		       
For more details click Exception
NSString *storageName = @"geoTest";
double lat = -73.99171;  
double lng = 40.738868; 
int resultLimit	= 2;		 			

Geo *geo = [geoService getNearByPoint:storageName latitude:lat longitude:lng resultLimit:resultLimit]; /* returns the Geo object. */
NSLog(@"geoStorageName is = %@",geo.storageName);
NSLog(@"sourceLat is = %@",geo.sourceLat);
NSLog(@"distanceInKM is = %@",geo.distanceInKM);
NSLog(@"sourceLng is = %@",geo.sourceLng);
NSMutableArray *pointList =  geo.pointList;
for(GeoPoint *point in pointList)
{
	NSLog(@"lat is = %@",point.latitude);
	NSLog(@"long is = %@",point.longitude);
	NSLog(@"marker is = %@",point.marker);
} 
NSString *jsonResponse = [geo toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "geo": {
                "storage": {
                    "storageName": "geoTest",
                    "sourceLat": -73.99171,
                    "sourceLng": 40.738868,
                    "distanceInKM": null,
                    "points": {
                        "point": [
                            {
                                "lat": -73.99171,
                                "lng": 40.73887,
                                "marker": "10gen Office"
                            },
                            {
                                "lat": -73.99249,
                                "lng": 40.738674,
                                "marker": "City Bakery"
                            }
                        ]
                    }
                }
            }
        }
    }
}
-(Geo*)getPointsWithInCircle:(NSString*)storageName latitude:(NSDecimalNumber*)lat longitude:(NSDecimalNumber*)lng radiusInKM:(NSDecimalNumber*)radiusInKM resultLimit:(int)resultLimit

Search the near by point from specified source point with in specified radius. Points to be searched should already be stored on cloud using unique storage name handler.

Parameters:

storageName - Unique handler for storage name
lat - Lattitude of source point
lng - Longitude of source point
radiusInKM - Radius in KM
resultLimit - Maximum number of results to be retrieved

Returns:

Geo object containing the target points in ascending order of distance from source point.

Response: Geo Object

Exception:

The method throws the following exception with the error code.
/* 
2901 - NOT FOUND - No destination found using given parameter Lat : '<lat>'  Long : '<lng>' and Radius In KM '<radiusInKM>'.
*/ 		       
For more details click Exception
NSString *storageName = @"geoTest";
double lat = -73.99171;  
double lng = 40.738868;  
double radiusInKM = 1;
int resultLimit	= 1;				

Geo *geo = [geoService getPointsWithInCircle:storageName latitude:lat longitude:lng radiusInKM:radiusInKM resultLimit:resultLimit]; /* returns the Geo object. */
NSLog(@"geoStorageName is = %@",geo.storageName);
NSLog(@"sourceLat is = %@",geo.sourceLat);
NSLog(@"distanceInKM is = %@",geo.distanceInKM);
NSLog(@"sourceLng is = %@",geo.sourceLng);
NSMutableArray *pointList =  geo.pointList;
for(GeoPoint *point in pointList)
{
	NSLog(@"lat is = %@",point.latitude);
	NSLog(@"long is = %@",point.longitude);
	NSLog(@"marker is = %@",point.marker);
} 
NSString *jsonResponse = [geo toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "geo": {
                "storage": {
                    "storageName": "geoTest",
                    "sourceLat": -73.99171,
                    "sourceLng": 40.738868,
                    "distanceInKM": null,
                    "points": {
                        "point": {
                            "lat": -73.99249,
                            "lng": 40.738674,
                            "marker": "City Bakery"
                        }
                    }
                }
            }
        }
    }
}
-(NSArray*)getAllStorage

Fetch the name of all storage stored on the cloud.

Parameters:

N/A

Returns:

Geo object containing List of all the storage created

Response: ArrayList<Geo> Object

Exception:

The method throws the following exception with the error code.
/* 
2902 - NOT FOUND - No Geo Storage exists.
*/ 		       
For more details click Exception
NSArray *geoList = [geoService getAllStorage]; /* returns the list of Geo object. */
for(Geo *geo in geoList){
	NSLog(@"storageName is = %@",geo.storageName);
	NSLog(@"createdOn is = %@",geo.createdOn);
}

NSString *jsonResponse = [geo toString]; /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "geo": {
                "storage": [
                    {
                        "storageName": "geoTest",
                        "createdOn": "2012-05-10T06:13:39.000Z"
                    },
                    {
                        "storageName": "GEO Storage",
                        "createdOn": "2012-05-10T06:48:12.000Z"
                    }
                ]
            }
        }
    }
}
-(Geo*)getAllPoints:(NSString*)storageName

Get All Point from storage.

Parameters:

storageName - Name of the storage from which ponits have to be fetched

Returns:

Geo object containing all the stored Geo Points for the specified storage

Response: Geo Object

Exception:

The method throws the following exception with the error code.
/* 
2904 - NOT FOUND - No Geo Points in the storage '<storageName>' exist.
*/ 		      
For more details click Exception
NSString *storageName = @"geoTest";

Geo *geo = [geoService getAllPoints:storageName]; /* returns the Geo object. */
NSString *storageName = geo.storageName;
NSMutableArray *pointList =  geo.pointList;
for(GeoPoint *point in pointList)
{
	NSLog(@"lat is = %@",point.latitude);
	NSLog(@"long is = %@",point.longitude);
	NSLog(@"marker is = %@",point.marker);
} 
NSString *jsonResponse = [geo toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "geo": {
                "storage": {
                    "storageName": "geoTest",
                    "points": {
                        "point": [
                            {
                                "lat": -73.99171,
                                "lng": 40.73887,
                                "marker": "10gen Office"
                            },
                            {
                                "lat": -73.98814,
                                "lng": 40.741405,
                                "marker": "Flatiron Building"
                            },
                            {
                                "lat": -73.99781,
                                "lng": 40.73913,
                                "marker": "Players Club"
                            },
                            {
                                "lat": -73.99249,
                                "lng": 40.738674,
                                "marker": "City Bakery"
                            },
                            {
                                "lat": -73.99249,
                                "lng": 40.738674,
                                "marker": "Splash Bar"
                            },
                            {
                                "lat": -73.98584,
                                "lng": 40.731697,
                                "marker": "Momofuku Milk Bar"
                            },
                            {
                                "lat": -73.9882,
                                "lng": 40.74164,
                                "marker": "Shake Shack"
                            },
                            {
                                "lat": -73.99408,
                                "lng": 40.75057,
                                "marker": "Penn Station"
                            },
                            {
                                "lat": -73.98602,
                                "lng": 40.74894,
                                "marker": "Empire State Building"
                            },
                            {
                                "lat": -73.99756,
                                "lng": 40.73083,
                                "marker": "Washington Square Park"
                            },
                            {
                                "lat": 106.9154,
                                "lng": 47.9245,
                                "marker": "Ulaanbaatar, Mongolia"
                            },
                            {
                                "lat": -74.2713,
                                "lng": 40.73137,
                                "marker": "Maplewood, NJ"
                            }
                        ]
                    }
                }
            }
        }
    }
}
-(App42Response*)deleteStorage:(NSString*)storageName

Delete the specifed Geo Storage from Cloud

Parameters:

StorageName - Name of the storage that has to be deleted

Returns:

App42Response if deleted successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code.
/* 
2903 - NOT FOUND - No Geo Storage exists with name '<storageName>'.
*/ 	       
For more details click Exception
String storageName = "geoTest";
						
App42Response *response = [geoService deleteStorage:storageName]; /* returns the Geo object. */
BOOL success =  response.isResponseSuccess; 
NSString *jsonResponse = [response toString]; /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "geo": {
                "storage": {
                    "storageName": "geoTest",
                    "createdOn": "2012-05-10T06:13:39.000Z"
                }
            }
        }
    }
}