function getCachePoints($cacheId) { $db = \lib\Database\DataBaseSingleton::Instance(); $queryCacheData = 'SELECT * FROM caches WHERE cache_id = :1 LIMIT 1'; $db->multiVariableQuery($queryCacheData, $cacheId); $cacheData = $db->dbResultFetch(); $typePoints = powerTrailBase::cacheTypePoints(); $sizePoints = powerTrailBase::cacheSizePoints(); $typePoints = $typePoints[$cacheData['type']]; $sizePoints = $sizePoints[$cacheData['size']]; $url = 'http://maps.googleapis.com/maps/api/elevation/xml?locations=' . $cacheData['latitude'] . ',' . $cacheData['longitude'] . '&sensor=false'; $altitude = simplexml_load_file($url); $altitude = round($altitude->result->elevation); if ($altitude <= 400) { $altPoints = 1; } else { $altPoints = 1 + ($altitude - 400) / 200; } $difficPoint = round($cacheData['difficulty'] / 3, 2); $terrainPoints = round($cacheData['terrain'] / 3, 2); return $altPoints + $typePoints + $sizePoints + $difficPoint + $terrainPoints; }