foreach ($cities_to_add as $city) { $new_city = new org_routamc_positioning_city_dba(); $new_city->city = $city['city']; $new_city->country = $city['country']; $new_city->latitude = $city['latitude']; $new_city->longitude = $city['longitude']; $stat = $new_city->create(); if ($stat) { $cities[] = $new_city; } }*/ $user = midcom::get('auth')->user->get_storage(); $user_position = new org_routamc_positioning_person($user); $coordinates = $user_position->get_coordinates(); if (!$coordinates) { throw new midcom_error("Failed to get your current position."); } echo "<p>" . sprintf('Your position is %s', org_routamc_positioning_utils::pretty_print_coordinates($coordinates['latitude'], $coordinates['longitude'])) . "</p>\n"; $run_times = 1; $run = 0; $total_time = 0; while ($run < $run_times) { $run++; $start = microtime(); $closest = org_routamc_positioning_utils::get_closest('org_routamc_positioning_city_dba', $coordinates, 10); echo "<p>Closest places to you are:<br />"; echo "<ol>\n"; foreach ($closest as $city) {
public static function get_location_for_person(midcom_db_person $person, $when = null) { $person_position = new org_routamc_positioning_person($person); return $person_position->get_coordinates($when); }
/** * Get coordinates of the object * * @return Array */ function get_coordinates($person = null, $time = null, $cache = true) { $coordinates = array('latitude' => null, 'longitude' => null, 'altitude' => null); if (is_a($this->_object, 'midcom_db_person')) { // This is a person record. Seek log $user_position = new org_routamc_positioning_person($this->_object); return $user_position->get_coordinates($time); } if (is_null($time)) { if (!isset($this->_object->metadata->published)) { //return null; $time = time(); } $time = $this->_object->metadata->published; } // Check if the object has a location set $location = $this->seek_location_object(); if (is_object($location) && $location->guid) { $coordinates['latitude'] = $location->latitude; $coordinates['longitude'] = $location->longitude; $coordinates['altitude'] = $location->altitude; // Consistency check if ($location->date != $time) { if ($location->log) { // We are most likely pointing to wrong log. Remove this cached entry so we can recreate i // again below midcom::get('auth')->request_sudo('org.routamc.positioning'); $location->delete(); $cache = true; midcom::get('auth')->drop_sudo(); } else { // This location entry isn't coming from a log so it just needs to be rescheduled midcom::get('auth')->request_sudo('org.routamc.positioning'); $location->date = $time; $location->update(); midcom::get('auth')->drop_sudo(); return $coordinates; } } else { return $coordinates; } } // No location set, seek based on creator and creation time $log = $this->seek_log_object($person, $time); if (is_object($log)) { $coordinates['latitude'] = $log->latitude; $coordinates['longitude'] = $log->longitude; $coordinates['altitude'] = $log->altitude; if ($cache) { // Cache the object's location into a location object midcom::get('auth')->request_sudo('org.routamc.positioning'); $location = new org_routamc_positioning_location_dba(); $location->log = $log->id; $location->relation = (int) ORG_ROUTAMC_POSITIONING_RELATION_IN; $location->date = $time; $location->parent = $this->_object->guid; $location->parentclass = get_class($this->_object); // TODO: Save parent component $location->latitude = $log->latitude; $location->longitude = $log->longitude; $location->altitude = $log->altitude; $location->create(); midcom::get('auth')->drop_sudo(); } return $coordinates; } // No coordinates found, return null return null; }
/** * Get coordinates of the object * * @return org_routamc_positioning_spot */ function get_coordinates($person = null, $time = null, $cache = true) { if (is_a($this->object, 'midgard_person') || is_a($this->object, 'org_openpsa_person')) { // This is a person record. Seek log $user_position = new org_routamc_positioning_person($this->object); return $user_position->get_coordinates($time); } if (is_null($time)) { if (!isset($this->object->metadata->published)) { //return null; $time = time(); } $time = $this->object->metadata->published; } // Check if the object has a location set $location = $this->seek_location_object(); if (is_object($location) && $location->guid) { $spot = new org_routamc_positioning_spot($location); // Consistency check if ($location->date != $time) { if ($location->log) { // We are most likely pointing to wrong log. Remove this cached entry so we can recreate i // again below $location->delete(); $cache = true; } else { // This location entry isn't coming from a log so it just needs to be rescheduled $location->date = $time; $location->update(); return $spot; } } else { return $spot; } } // No location set, seek based on creator and creation time $log = $this->seek_log_object($person, $time); if (is_object($log)) { $spot = new org_routamc_positioning_spot($log); if ($cache) { // Cache the object's location into a location object $location = new org_routamc_positioning_location(); $location->log = $log->id; $location->relation = (int) org_routamc_positioning::RELATION_IN; $location->date = $time; $location->parent = $this->object->guid; $location->parentclass = get_class($this->object); // TODO: Save parent component $location->latitude = $log->latitude; $location->longitude = $log->longitude; $location->altitude = $log->altitude; $location->create(); } return $spot; } // No coordinates found, return null return null; }