public function test_set_anonymous()
 {
     $this->markTestSkipped();
     $_SESSION = array();
     // Midgard airport (FYMG)
     $fymg = new midgardmvc_helper_location_spot(-22.083332, 17.366667);
     $this->assertTrue(midgardmvc_helper_location_user::set_location($fymg));
 }
 /**
  * Update user's location
  */
 public function post_location(array $args)
 {
     if (isset($_POST['latitude']) && isset($_POST['longitude'])) {
         $spot = new midgardmvc_helper_location_spot((double) $_POST['latitude'], (double) $_POST['longitude']);
         if (isset($_POST['text'])) {
             // User has provided a textual location
             $spot->text = $_POST['text'];
         } else {
             try {
                 // Get textual location by reverse geocoding
                 $geocoder = new midgardmvc_helper_location_geocoder_geonames();
                 $city = $geocoder->reverse_geocode($spot);
                 if ($city->text) {
                     $spot->text = $city->text;
                 }
             } catch (Exception $e) {
                 // Ignore silently
             }
         }
     } elseif (isset($_POST['text'])) {
         $spot = new midgardmvc_helper_location_spot($_POST['text']);
     } else {
         throw new InvalidArgumentException("Expected latitude and longitude, or text not found");
     }
     if (isset($_POST['accuracy'])) {
         // W3C accuracy is in meters, convert to our approximates
         if ($_POST['accuracy'] < 30) {
             // Exact enough
             $spot->accuracy = 10;
         } elseif ($_POST['accuracy'] < 400) {
             // Postal code area
             $spot->accuracy = 20;
         } elseif ($_POST['accuracy'] < 5000) {
             // City
             $spot->accuracy = 30;
         } else {
             // Fall back to "state level"
             $spot->accuracy = 50;
         }
     }
     $spot->source = 'browser';
     if (!midgardmvc_helper_location_user::set_location($spot)) {
         throw new midgardmvc_exception_httperror("Failed to store location");
     }
     midgardmvc_core::get_instance()->log("postlocation", "Location stored", 'debug');
     $this->get_location($args);
 }