示例#1
0
 /**
  * 
  * @param GMapCoord $gmap_coord
  * @return boolean $is_inside
  * @author fabriceb
  * @since Jun 2, 2009 fabriceb
  */
 public function containsGMapCoord(GMapCoord $gmap_coord)
 {
   $is_inside = 
     (
     $gmap_coord->getLatitude() < $this->getNorthEast()->getLatitude()
     &&
     $gmap_coord->getLatitude() > $this->getSouthWest()->getLatitude()
     &&
     $gmap_coord->getLongitude() < $this->getNorthEast()->getLongitude()
     &&
     $gmap_coord->getLongitude() > $this->getSouthWest()->getLongitude()
     );
 
   return $is_inside;
 }
示例#2
0
   /**
  * very approximate calculation of the distance in kilometers between two coordinates
  * @param GMapCoord $coord1
  * @param GMapCoord $coord2
  * @return float
  * @author fabriceb
  * @since 2009-05-03
  */
 public static function distance($coord1, $coord2)
 {
 
   return $coord1->distanceFrom($coord2);
 }
示例#3
0
//$app='frontend';
//include(dirname(__FILE__).'/../bootstrap/functional.php');



$lat = 48.856536;
$lng =  2.339307;
$zoom = 11;

$pix = GMapCoord::fromLatToPix($lat, $zoom);
$ne_lat = GMapCoord::fromPixToLat($pix - 150, $zoom);
$sw_lat = GMapCoord::fromPixToLat($pix + 150, $zoom);

$pix = GMapCoord::fromLngToPix($lng, $zoom);
$sw_lng = GMapCoord::fromPixToLng($pix - 150, $zoom);
$ne_lng = GMapCoord::fromPixToLng($pix + 150, $zoom);

$bounds = new GMapBounds(new GMapCoord($sw_lat,$sw_lng),new GMapCoord($ne_lat,$ne_lng));

$t = new lime_test(15, new lime_output_color());

$t->diag('GMapBounds test');

$t->diag('->__toString Test');
$t->is($bounds->__toString(),'((48.7887237041, 2.23631017383), (48.9242565582, 2.44230382617))','On a déduit correctement les bounds à partir de la largeur de la carte, le centre et le zoom');

$t->diag('->getZoom Test');

$bounds_world = GMapBounds::createFromString('((-90, -180), (90, 180))');
$t->is($bounds_world->getZoom(256),0,'Pour voir le monde sur une largeur/hauteur de 256 pix, il faut un zoom 0');
 /**
  * exact distance with Haversine formula
  *
  * @param GMapCoord $coord1
  * @param GMapCoord $coord2
  * @return float
  * @see exactDistanceFrom
  *
  * @author fabriceb
  * @since Apr 21, 2010
  */
 public static function exactDistance($coord1, $coord2)
 {
     return $coord1->exactDistanceFrom($coord2);
 }
$lat = 0;
$lng = 0;
$zoom = 0;
$pix = GMapCoord::fromLatToPix($lat, $zoom);
$t->is($pix, 128, 'Latitude 0 is at the middle of the map for zoom 0');
$pix = GMapCoord::fromLngToPix($lng, $zoom);
$t->is($pix, 128, 'Longitude 0 is at the middle of the map for zoom 0');
$lat = 0;
$lng = -180;
$zoom = 12;
$pix = GMapCoord::fromLatToPix($lat, $zoom);
$t->is($pix, 256 * pow(2, $zoom - 1), 'Latitude 0 is at the middle of the map whatever the zoom');
$pix = GMapCoord::fromLngToPix($lng, $zoom);
$t->is($pix, 0, 'Longitude -180 is at the left of the map whathever the zoom');
$coord_paris = new GMapCoord(48.857939, 2.346611);
$coord_le_mans = new GMapCoord(48.007381, 0.202131);
$t->is(round(GMapCoord::distance($coord_le_mans, $coord_paris)), 257, 'Approximate distance between Le Mans and Paris is 257');
$t->is(round(GMapCoord::exactDistance($coord_le_mans, $coord_paris), 4), 184.5783, 'Approximate distance between Le Mans and Paris is 257');
$t->is(round(GMapCoord::exactDistanceSLC($coord_le_mans, $coord_paris), 4), 184.3091, 'Approximate distance between Le Mans and Paris is 257');
$coord_luxembourg = new GMapCoord(48.846559, 2.340689);
$coord_saint_michel = new GMapCoord(48.853717, 2.344015);
$t->is(round(GMapCoord::distance($coord_luxembourg, $coord_saint_michel) * 1000), 879, 'Approximate distance between RER Luxembourg and Saint-Michel is 879 meters');
$t->is(round(GMapCoord::exactDistance($coord_luxembourg, $coord_saint_michel) * 1000, 4), 833.4828, 'Approximate distance between RER Luxembourg and Saint-Michel is 879 meters');
$t->is(round(GMapCoord::exactDistanceSLC($coord_luxembourg, $coord_saint_michel) * 1000, 4), 832.2670000000001, 'Approximate distance between RER Luxembourg and Saint-Michel is 879 meters');
$coord_luxembourg = new GMapCoord(48.846559, 2.340689);
$coord_saint_michel = new GMapCoord(48.853717, 2.344015);
$center_of_the_world = new GMapCoord(0, 0);
$bounds_paris = GMapBounds::createFromString('((48.791033113791144, 2.2240447998046875), (48.926559723513435, 2.4300384521484375))');
$t->ok($coord_saint_michel->isInsideBounds($bounds_paris), 'Saint-Michel Notre-Dame is in Paris');
$t->ok($coord_luxembourg->isInsideBounds($bounds_paris), 'RER Luxembourg is in Paris');
$t->ok(!$center_of_the_world->isInsideBounds($bounds_paris), 'Center of the world is not in Paris (amazingly)');
示例#6
0
 /**
 *
 * @param GMapMarker[] $markers array of MArkers
 * @return GMapCoord
 * @author fabriceb
 * @since 2009-05-02
 *
 **/
 public static function getMassCenterCoord($markers)
 {
   $coords = array();
   foreach($markers as $marker)
   {
     array_push($coords, $marker->getGMapCoord());
   }
  
   return GMapCoord::getMassCenterCoord($coords);
 }