public function equals(Coordinate $otherCoord) { if ($otherCoord->getLatitude() == $this->latitude && $otherCoord->getLongitude() == $this->longitude) { return true; } return false; }
/** * @param Coordinate $coordinate * @param array $distanceUnit * * @return float */ public function distanceFrom(Coordinate $coordinate, array $distanceUnit = null) { if ($distanceUnit === null) { $distanceUnit = DistanceUnit::KM; } $theta = $this->getLongitude()->toNative() - $coordinate->getLongitude()->toNative(); $dist = sin(deg2rad($this->getLatitude()->toNative())) * sin(deg2rad($coordinate->getLatitude()->toNative())) + cos(deg2rad($this->getLatitude()->toNative())) * cos(deg2rad($coordinate->getLatitude()->toNative())) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $unit = $dist * 60 * $distanceUnit; return round($unit, 1); }
/** * The 'nearest' implementation of the OSRM server API. * https://github.com/DennisOSRM/Project-OSRM/wiki/Server-api * * @param \Osrm\Coordinate $coordinate * @return type */ public function getNearestStreetPoint(Coordinate $coordinate) { $this->prepareServerUrl(); $requestUrl = $this->server . 'nearest?' . $coordinate; $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $requestUrl)); $resp = curl_exec($curl); curl_close($curl); $json = json_decode($resp); if ($json->status === 200) { $latitude = $json->mapped_coordinate[0]; $longitude = $json->mapped_coordinate[1]; $name = $json->name; $retCoord = new Coordinate($latitude, $longitude); $retCoord->setName($name); return $retCoord; } else { throw new OsrmException("Osrm status error", $json->{'status'}); return null; } }
/** * @param Coordinate $otherCoordinate * @return bool */ public function equals(Coordinate $otherCoordinate) { return $otherCoordinate->getLatitude() == $this->latitude && $otherCoordinate->getLongitude() == $this->longitude; }
public function testToString() { $c = new Coordinate(1.1, 2.2); $this->assertEquals("1.1,2.2", $c->__toString()); }
/** * @param $string * @return LightSwitchCommand */ public function parseCommand($string) { if (preg_match('/(toggle|turn on|turn off) (.*) through (.*)/', $string, $matches) == 0) { throw new \InvalidArgumentException('Could not parse the instruction "' . $string . '"'); } switch ($matches[1]) { case 'toggle': $command = LightSwitchCommand::COMMAND_TOGGLE; break; case 'turn on': $command = LightSwitchCommand::COMMAND_ON; break; case 'turn off': default: $command = LightSwitchCommand::COMMAND_OFF; } return new LightSwitchCommand(Coordinate::fromString($matches[2]), Coordinate::fromString($matches[3]), $command); }
} // This takes the values are stored in our variables, // and simply displays them. public function display() { echo $this->_lat; echo $this->_long; } public function getLatitude() { return $this->_lat; } public function getLongitude() { return $this->_long; } } // This creates a new Coordinate "object". 25 and 5 have been stored inside. $coordinate = new Coordinate(25, 5); // 25 and 5 are now stored in $coordinate. $coordinate->display(); // Since $coordinate already "knows" about 25 and 5 // it can display them. // It's important to note, that each time you run "new Coordinate", // you're creating an new "object" that isn't linked to the other objects. $coord2 = new Coordinate(99, 1); $coord2->display(); // This will print 99 and 1, not 25 and 5. // $coordinate is still around though, and still knows about 25 and 5. $coordinate->display(); // Will still print 25 and 5.
/** * @throws \InvalidArgumentException * * @param Coordinate $latitude * @param Coordinate $longitude */ private function assertConstraintsNotViolated(Coordinate $latitude, Coordinate $longitude) { abs($latitude->asDecimal()) <= self::LATITUDE_MAX_VAL || $this->throwException(sprintf('Latitude should be equal or greater than %f and equal or less than %f.', -self::LATITUDE_MAX_VAL, self::LATITUDE_MAX_VAL)); abs($longitude->asDecimal()) <= self::LONGITUDE_MAX_VAL || $this->throwException(sprintf('Longitude should be equal or greater than %f and equal or less than %f.', -self::LONGITUDE_MAX_VAL, self::LONGITUDE_MAX_VAL)); }
/** * Chage the current coordinate location to match the passed coordinate * location * * @param \Jaguar\Coordinate $coordinate * * @return \Jaguar\Coordinate */ public function setLocation(Coordinate $coordinate) { return $this->setX($coordinate->getX())->setY($coordinate->getY()); }
public function testGetOriginalAxis() { $coordinate = new Coordinate(1, 2); $this->assertEquals(1, $coordinate->getOriginalXAxis()); $this->assertEquals(2, $coordinate->getOriginalYAxis()); }
function _getCoordinates($city, $state) { $coordinates = new Coordinate(); $coordinates->where('city', $city)->where('state', $state)->get(); if (!$coordinates->exists()) { $data = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=" . urlencode($city) . "," . urlencode($state) . "&sensor=false"); $json_array = json_decode($data, true); $lat = $json_array['results'][0]['geometry']['location']['lat']; $long = $json_array['results'][0]['geometry']['location']['lng']; $c = new Coordinate(); $c->city = $city; $c->state = $state; $c->lat = $lat; $c->lng = $long; $c->save(); } else { $lat = $coordinates->lat; $long = $coordinates->lng; } return array($lat, $long); }
/** * @covers Application\Math\Coordinate::haversineGreatCircleDistance */ public function testHaversineGreatCircleDistance() { $this->assertEquals((string) 21988.88835545, (string) $this->object->haversineGreatCircleDistance(52.1490617, 5.366273, 52.056364, 5.081895)); }
public function __toString() { return implode(',', [$this->topLeft->getX(), $this->topLeft->getY(), $this->bottomRight->getX(), $this->bottomRight->getY()]); }