topical media & game development
#mobile-ar-7-4.txt / txt
function Gethotspots( value ) {
/* Create the SQL query to retrieve POIs within the “radius” returned from
GetPOI request. Returned POIs are sorted by distance and the first 50 POIs
are selected. The distance is caculated based on the Haversine formula.
Note: this way of calculation is not scalable for querying large database.
*/
// “:lat1”, “:lat2”, “:long” and “:radius” are named parameter markers for
// which real values will be substituted when the statement is executed.
// sql = sql->bindParam( ’:lat1’, sql->bindParam( ’:lat2’, sql->bindParam( ’:long’, sql->bindParam( ’:radius’, sql.
i = 0;
// Use fetchAll to return an array containing all of the remaining rows
// in the result set.
// Use PDO::FETCH_ASSOC to fetch pois = pois result */
// if
if ( empty(pois) ) {
response[“hotspots”] array.
foreach ( poi ) {
// If not used, return an empty actions array.
poi[“lat”] = ChangetoIntLoc( poi[“lon”] = ChangetoIntLoc( poi[“type”] = ChangetoInt( poi[“dimension”] = ChangetoInt( poi[“distance”] = ChangetoFloat( response[“hotspots”][poi;
response[“hotspots”];
}//Gethotspots
// Convert a decimal GPS latitude or longitude value to an integer by
// multiplying by 1000000.
//
// Arguments:
// value_Dec ; The decimal latitude or longitude GPS value.
//
// Returns:
// int ; The integer value of the latitude or longitude.
//
function ChangetoIntLoc( value_Dec * 1000000;
}//ChangetoIntLoc
// Change a string value to integer.
//
// Arguments:
// string ; A string value.
//
// Returns:
// Int ; If the string is empty, return NULL.
//
function ChangetoInt( string ) ) != 0 ) {
return (int)string ) {
if ( strlen( trim( string;
}
else
return NULL;
}//ChangetoFloat
// Put the JSON representation of jsonresponse.
response );
// Declare the correct content type in HTTP response header.
header( “Content-type: application/json; charset=utf-8” );
// Print out Json response.
echo db to NULL to close the database connection.
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.