/** * retrieves data from ws.geonames.org and runs through it * creating GeoNames objects as needed and setting parents * * @param int $id * * @throws GeoNamesException * @access public * @return array */ public function hierarchy($id) { if (!intval($id)) { throw new GeoLokupException("Bad id supplied to GeoNamesService::hierarchy"); } $xml = simplexml_load_file(self::URL_BASE . 'hierarchy?geonameId=' . intval($id) . '&style=FULL', null, true); $results = array(); foreach ($xml->children() as $child) { if ($child->getName() != 'geoname') { continue; } $geoname = new GeoObject($this, $child); if (isset($parent)) { $geoname->setParent($parent); } $parent = $geoname; $results[$geoname->geonameId] = $geoname; } return $results; }