App42 Cloud API

Windows Phone Cloud SDK

Geo Spatial

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 create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.

ServiceAPI api= new ServiceAPI("<API_KEY>","<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 = api.BuildGeoService();

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

The Windows Phone API's work in an asynchronous mode that means the response will not be available immediately and all the API methods would not return any value and have return type as void. The response will be returned in callback methods which the caller will provide to the calling method.
As mentioned above that the response will be returned in callback methods, every API method is taking instance of App42Callback (as the last parameter) which will have the implementation of 2 methods: OnSuccess & OnException.(as shown below)

public class CallBack : App42Callback
{
public override void OnSuccess(Object obj)
{
Geo geo = (Geo) obj;
//Do whatever you want with the user object
}
public override void OnException(App42Exception e)
{
//Do whatever you want with the exception
}
}

The callback methods will return the response in the form of Object which will have to be type cast to the object domain object (e.g. App42Response / Geo / IList in this case) The Domain object 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.

public override void OnSuccess(Object obj)
{
Geo geo = (Geo) obj;
String pointList =  geo.GetPointList(); 
String 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 exists with name '<storageName>'".

		public override void OnException(App42Exception ex)
		{
			int appErrorCode = ex.GetAppErrorCode();
			int httpErrorCode = ex.GetHttpErrorCode();
			
			String jsonText = ex.GetMessage(); /* returns the Exception text in JSON format. (as shown below)*/	
		}
                            
	{
	   "app42Fault": {
		   "httpErrorCode": 404,
		   "appErrorCode": 2903,
		   "message": "Not Found",
		   "details": "No Geo Storage exists with name 'geoTest'"
	   }
	}							

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.

public void CreateGeoPoints(String geoStorageName, IList<String> geoPointsList, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

Geo object containing list of Geo Points that have been saved

Response: Geo Object

For more details click Exception
IList geoPointsList = new List();					
GeoPoint gp = new GeoPoint();
gp.SetMarker("Maplewood, NJ");
gp.SetLat(-74.2713);
gp.SetLng(40.73137);
geoPointsList.Add(gp);

geoService.CreateGeoPoints(geoStorageName,geoPointsList,requestCallback); /* returns the Geo object. */
OnSuccess(Object obj){
Geo geo = (Geo) obj;
String storageName = geo.GetStorageName();  
IList<Point> pointList =  geo.GetPointList(); 
for(int i=0;i < pointList.Count;i++)
{  
Console.WriteLine("lat is " + pointList[i].GetMarker());
Console.WriteLine("lng is " +  pointList[i].GetLat());
Console.WriteLine("marker is " + pointList[i].GetLng());		
}  
String jsonResponse = pointList.ToString(); /* returns the response in JSON format. (as shown below)*/
}
{

    "app42": {

        "response": {

            "success": true,

            "geo": {

                "storage": {

                    "storageName": "geoTest",

                    "points": {

                        "point": {

                            "lat": -74.2713,

                            "lng": 40.73137,

                            "marker": "Maplewood, NJ"

                        }

                    }

                }

            }

        }

    }

} 
public void GetNearByPointsByMaxDistance(String storageName, Double lat, Double lng, Double distanceInKM, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

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

Response: Geo Object

Exception:

This method throws following exception.
/* 
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
String storageName = "geoTest";
double  lat = -73.99171;
double  lng = 40.738868;
double distanceInKM = 1;

geoService.GetNearByPointsByMaxDistance(storageName, lat, lng, distanceInKM,requestCallback); /* returns the Geo object. */
OnSuccess(Object obj)
{
Geo geo = (Geo) obj;
Console.WriteLine("geoStorageName is " + geo.GetStorageName());
Console.WriteLine("sourceLat is " +  geo.GetSourceLat());
Console.WriteLine("sourceLng is " + geo.GetSourceLng());
Console.WriteLine("distanceInKM is " + geo.GetDistanceInKM());
IList<Point> pointList =  geo.GetPointList(); 
for(int i=0;i < pointList.Count;i++)
{  
Console.WriteLine("lat is " + pointList[i].GetMarker());
Console.WriteLine("lng is " +  pointList[i].GetLat());
Console.WriteLine("marker is " + pointList[i].GetLng());
}  
String jsonResponse = pointList.ToString(); /* returns the response in JSON format. (as shown below)*/        
{
    "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"
                            }
                        ]
                    }
                }
            }
        }
    }
}
public void GetNearByPoint(String storageName, double lat, double lng, double resultLimit, App42Callback requestCallback)

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:

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

Geo geo = geoService.GetNearByPoint(storageName, lat, lng, resultLimit); /* returns the Geo object. */
Console.WriteLine("geoStorageName is " + geo.GetStorageName());
Console.WriteLine("sourceLat is " + geo.GetSourceLat());
Console.WriteLine("distanceInKM is " + geo.GetDistanceInKM());
Console.WriteLine("sourceLng is " + geo.GetSourceLng());	
IList<Geo.Point> pointList =  geo.GetPointList(); 
for (int i=0;i < pointList.Count;i++)
{
Console.WriteLine("lat is " + pointList[i].GetMarker());
Console.WriteLine("lng is " +  pointList[i].GetLat());
Console.WriteLine("marker is " + pointList[i].GetLng());		
}
String jsonResponse = geo.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "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"
                            }
                        ]
                    }
                }
            }
        }
    }
}
public void GetPointsWithInCircle(String storageName,Double lat, Double lng,Double radiusInKM, int resultLimit, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

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

Response: Geo Object

Exception:

This method throws following exception.
/*  
2901 - NOT FOUND - No destination found using given parameter Lat : '<lat>'  Long : '<lng>' and Radius In KM '<radiusInKM>'.
*/ 		       
For more details click Exception
geoService.GetPointsWithInCircle(storageName,lat,lng,radiusInKM,resultLimit,requestCallback); /* returns the Geo object. */
OnSuccess(Object obj)
{
Geo geo = (Geo) obj;
Console.WriteLine("geoStorageName is " + geo.GetStorageName());
Console.WriteLine("sourceLat is " +  geo.GetSourceLat());
Console.WriteLine("sourceLng is " + geo.GetSourceLng());
Console.WriteLine("distanceInKM is " + geo.GetDistanceInKM());
IList<Point> pointList =  geo.GetPointList(); 
for(int i=0;i < pointList.Count;i++)
{  
Console.WriteLine("lat is " + pointList[i].GetMarker());
Console.WriteLine("lng is " +  pointList[i].GetLat());
Console.WriteLine("marker is " + pointList[i].GetLng()); 
}  
String jsonResponse = pointList.ToString(); /* returns the response in JSON format. (as shown below)*/
}
{
    "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"
                        }
                    }
                }
            }
        }
    }
}
public void GetAllStorage(App42Callback requestCallback)

Fetch the name of all storage stored on the cloud.

Parameters:

requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

Geo object containing list of all the storage created

Response: IList<Geo> Object

Exception:

This method throws following exception.
/* 
2902 - NOT FOUND - No Geo Storage exists.
*/ 		       
For more details click Exception
geoService.GetAllStorage(requestCallback); /* returns the list of Geo object. */
OnSuccess(Object obj)
{
IList<Geo> geoStorageList = (IList<Geo>) obj;
for(int i=0;i < geoStorageList.Count;i++)
{ 
Console.WriteLine("lat is " + geoStorageList[i].GetStorageName());
}
String jsonResponse = geoStorageList.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"
                    }
                ]
            }
        }
    }
}
public void GetAllPoints(String storageName, App42Callback requestCallback)

Get All Point from storage.

Parameters:

storageName - Name of the storage from which ponits have to be fetched
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

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

Response: Geo Object

Exception:

This method throws following exception.
/* 
2904 - NOT FOUND - No Geo Points in the storage '<storageName>' exist.
*/ 		      
For more details click Exception
geoService.GetAllPoints(storageName,requestCallback); /* returns the Geo object. */
OnSuccess(Object obj)
{
Geo geo = (Geo) obj;
String storageName = geo.GetStorageName();
IList<Point> pointList =  geo.GetPointList(); 
for(int i=0;i < pointList.Count;i++)
{  
Console.WriteLine("lat is " + pointList[i].GetMarker());
Console.WriteLine("lng is " +  pointList[i].GetLat());
Console.WriteLine("marker is " + pointList[i].GetLng());  
}  
String jsonResponse = geo.ToString(); /* returns the response in JSON format. (as shown below)*/  
{
    "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"
                            }
                        ]
                    }
                }
            }
        }
    }
}
public void DeleteStorage(String storageName, App42Callback requestCallback)

Delete the specifed Geo Storage from Cloud

Parameters:

storageName - Name of the storage that has to be deleted
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

Geo object containing the name of the storage that has been deleted

Response: Geo Object

Exception:

This method throws following exception.
/* 
2903 - NOT FOUND - No Geo Storage exists with name '<storageName>'.
*/ 	       
For more details click Exception
geoService.DeleteStorage(storageName,requestCallback); /* returns the Geo object. */
OnSuccess(Object obj)
{
Geo geo = (Geo) obj;
Boolean success = geo.IsResponseSuccess();
String 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"
                }
            }
        }
    }
}