App42 Cloud API

PHP 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.

$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 = $api->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 user 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.

$geoStorageName = "geoTest";
$geoList = array();
$gp = new GeoPoint();
gp->setMarker("Maplewood, NJ");
gp.setLat(-74.2713);
gp.setLng(40.73137);
geoList.add(gp);

$geo = $geoService->createGeoPoints($geoStorageName,$geoList); /* returns the Geo object. */ 
$storageName =  geo->getStorageName();
$pointList =  $geo->getPointList(); 
foreach( $pointList as $point)
{
print_r("lat is" . $point->getLat());
print_r("lng is" . $point->getLng());
print_r("marker is" . $point->getMarker());
}
$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 Exception with message as "Not Found" and the appErrorCode as "2903" and the details as "No Geo Storage exists with name '<storageName>'.".

$storageName = "geoTest";
							
try{
	$geo = $geoService->deleteStorage($storageName);
   }
catch(App42Exception $ex) 
{
	$appErrorCode = $ex->getAppErrorCode();
	$httpErrorCode = $ex->getHttpErrorCode();
	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
}

	$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.

function createGeoPoints($geoStorageName, $geoPointsList)

Stores the geopints 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
$geoStorageName = "geoTest";
$geoList = array();					
$gp = new GeoPoint();
gp.setMarker("Maplewood, NJ");
gp.setLat((-74.2713);
gp.setLng(40.73137);
geoList.add(gp);

$geo = $geoService->createGeoPoints($geoStorageName,$geoList); /* returns the Geo object. */
$pointList =  $geo->getPointList(); 
{
print_r("lat is" . $point->getLat());
print_r("lng is" . $point->getLng());
print_r("marker is" . $point->getMarker());
} 
$jsonResponse = $geo->toString(); /* returns the response in JSON format. (as shown below)*/
                            
For more details click Exception
{

    "app42": {

        "response": {

            "success": true,

            "geo": {

                "storage": {

                    "storageName": "geoTest",

                    "points": {

                        "point": {

                            "lat": -74.2713,

                            "lng": 40.73137,

                            "marker": "Maplewood, NJ"

                        }

                    }

                }

            }

        }

    }

} 
function getNearByPointsByMaxDistance($storageName, $lat, $lng, $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:

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>'.
*/ 		  
        
$storageName = "geoTest";
$lat = "-73.99171";
$lng = "40.738868";
$distanceInKM = "1";

$geo = $geoService->getNearByPointsByMaxDistance($storageName, $lat, $lng, $distanceInKM); /* returns the Geo object. */
print_r("geoStorageName is " + $geo->getStorageName());
print_r("sourceLat is " + $geo->getSourceLat());
print_r("distanceInKM is " + $geo->getDistanceInKM());
print_r("sourceLng is " + $geo->getSourceLng());
$pointList =  $geo->getPointList(); 
for ($pointList as a $point)
{
print_r("lat is " + $point->getLat());
print_r("lng is " + $point->getLng());
print_r("marker is " + $point->getMarker());
}
$jsonResponse = $geo->toString(); /* returns the response in JSON format. (as shown below)*/
                            
For more details click Exception
{
    "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"
                            }
                        ]
                    }
                }
            }
        }
    }
}
function getNearByPoint($storageName, $lat, $lng, $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:

This method throws following exception.
/* 
2905 - NOT FOUND - No destination found using given parameter Lat : '<lat>'  Long : '<lng>'.
*/ 		  
        
$storageName = "geoTest";
$lat = -73.99171;  
$lng = 40.738868; 
$resultLimit = 2;
						
$geo = $geoService->getNearByPoint($storageName, $lat, $lng, $resultLimit); /* returns the Geo object. */
print_r("geoStorageName is " + $geo->getStorageName());
print_r("sourceLat is " + $geo->getSourceLat());
print_r("distanceInKM is " + $geo->getDistanceInKM());
print_r("sourceLng is " + $geo->getSourceLng()); 
$pointList =  $geo->getPointList();
for ($pointList as $point)
{
print_r("lat is " + $point->getLat());
print_r("lng is " + $point->getLng());
print_r("marker is " + $point->getMarker());		
}
$jsonResponse = $geo->toString(); /* returns the response in JSON format. (as shown below)*/
                            
For more details click Exception
{
    "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"
                            }
                        ]
                    }
                }
            }
        }
    }
}
function getPointsWithInCircle($storageName, $lat, $lng, $radiusInKM, $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:

This method throws following exception.
/*  
2901 - NOT FOUND - No destination found using given parameter Lat : '<lat>'  Long : '<lng>' and Radius In KM '<radiusInKM>'.
*/ 		  
        
$storageName = "geoTest";
$lat = "-73.99171";  
$lng = "40.738868";  
$radiusInKM = "1";
$resultLimit = "1";
						
$geo = $geoService->getPointsWithInCircle($storageName, $lat, $lng, $radiusInKM, $resultLimit); /*the Geo object. */
print_r("geoStorageName is " + $geo->getStorageName());
print_r("sourceLat is " + $geo->getSourceLat());
print_r("distanceInKM is " + $geo->getDistanceInKM());
print_r("sourceLng is " + $geo->getSourceLng());
$pointList =  $geo->getPointList();
for ($pointList as $point)
{
print_r("lat is " + $point->getLat());
print_r("lng is " + $point->getLng());
print_r("marker is " + $point->getMarker());
} 
$jsonResponse = $geo->toString(); /* returns the response in JSON format. (as shown below)*/
                            
For more details click Exception
{
    "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"
                        }
                    }
                }
            }
        }
    }
}
function 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: Geo Object

Exception:

This method throws following exception.
/* 
2902 - NOT FOUND - No Geo Storage exists. 
*/ 		  
        
$geoList = $geoService->getAllStorage(); /*the Geo object. */
foreach( $geoList as $geo )
{
$storageName =  $geo->getStorageName();
}
$jsonResponse = $geo->toString(); /* returns the response in JSON format. (as shown below)*/
For more details click Exception
{
    "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"
                    }
                ]
            }
        }
    }
}
function getAllPoints($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:

This method throws following exception.
/* 
2904 - NOT FOUND - No Geo Points in the storage '<storageName>' exist.
*/ 		  
        
$storageName = "geoTest";						
$geo = $geoService->getAllPoints($storageName); /*the Geo object. */
$storageName =  $geo->getStorageName();
$pointList =  $geo->getPointList(); 
for ($pointList as $points)
{
print_r("lat is " + $points->getLat());
print_r("lng is " + $points->getLng());
print_r("marker is " + $points->getMarker());
}
$jsonResponse = $geo->toString(); /* returns the response in JSON format. (as shown below)*/
For more details click Exception
{
    "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"
                            }
                        ]
                    }
                }
            }
        }
    }
}
function deleteStorage($storageName)

Delete the specifed Geo Storage from Cloud

Parameters:

storageName - Name of the storage that has to be deleted

Returns:

App42Response if removed successfully

Response: App42Response Object

Exception:

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