コード例 #1
0
 public function test_bounding_box_for_radius()
 {
     // Helsinki-Malmi airport (EFHF)
     $efhf = new midgardmvc_helper_location_spot(60.254558, 25.042828);
     // Get 20km bounding box
     $bbox = midgardmvc_helper_location_utils::get_bounding_box_for_radius($efhf, 20);
     $this->assertTrue(is_array($bbox));
     $this->assertEquals(count($bbox), 2);
     // Ensure the box limits are in right directions
     $this->assertEquals(midgardmvc_helper_location_utils::get_bearing($efhf, $bbox[0]), 'SW');
     $this->assertEquals(midgardmvc_helper_location_utils::get_bearing($efhf, $bbox[1]), 'NE');
     // Check that the distance to a corner is correct.
     // Note: using 2D trigonometry on 3D globe so numbers are not exact
     $distance1 = midgardmvc_helper_location_utils::get_distance($bbox[0], $efhf);
     $this->assertEquals(round($distance1), round(sqrt(pow(20, 2) + pow(20, 2))));
 }
コード例 #2
0
 /**
  * Pretty print a position mapping Microformatted city name or other label
  *
  * @return string
  */
 static function microformat_location(midgardmvc_helper_location_spot $spot)
 {
     $closest = midgardmvc_helper_location_utils::get_closest('midgardmvc_helper_location_city', $spot, 1);
     $latitude_string = midgardmvc_helper_location_utils::pretty_print_coordinate($spot->latitude);
     $latitude_string .= $spot->latitude > 0 ? ' N' : ' S';
     $longitude_string = midgardmvc_helper_location_utils::pretty_print_coordinate($spot->longitude);
     $longitude_string .= $spot->longitude > 0 ? ' E' : ' W';
     if (count($closest) == 0) {
         // No city found, generate only geo microformat
         $coordinates_string = "<span class=\"geo\">";
         $coordinates_string .= "<abbr class=\"latitude\" title=\"{$spot->latitude}\">{$latitude_string}</abbr> ";
         $coordinates_string .= "<abbr class=\"longitude\" title=\"{$spot->longitude}\">{$longitude_string}</abbr>";
         $coordinates_string .= "</span>";
         return $coordinates_string;
     }
     foreach ($closest as $city) {
         // City found, combine it and geo
         $city_string = "<span class=\"geo adr\">";
         $city_string .= "<abbr class=\"latitude\" title=\"{$spot->latitude}\">{$latitude_string}</abbr> ";
         $city_string .= "<abbr class=\"longitude\" title=\"{$spot->longitude}\">{$longitude_string}</abbr> ";
         $city_spot = new midgardmvc_helper_location_spot($city);
         $city_distance = round(midgardmvc_helper_location_utils::get_distance($spot, $city_spot));
         $city_label = "<span class=\"locality\">{$city->city}</span>, ";
         $city_label .= "<span class=\"country-name\">{$city->country}</span>";
         if ($city_distance <= 4) {
             $city_string .= $city_label;
         } else {
             $bearing = midgardmvc_helper_location_utils::get_bearing($city_spot, $spot);
             $city_string .= sprintf(midgardmvc_core::get_instance()->i18n->get_string('%skm %s of %s', 'midgardmvc_helper_location'), $city_distance, $bearing, $city_label);
         }
         $city_string .= "</span>";
     }
     return $city_string;
 }