本文整理汇总了PHP中Point::getLatitude方法的典型用法代码示例。如果您正苦于以下问题:PHP Point::getLatitude方法的具体用法?PHP Point::getLatitude怎么用?PHP Point::getLatitude使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point
的用法示例。
在下文中一共展示了Point::getLatitude方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFromCenterAndDistance
/**
* @param Point $center
* @param Distance $distance
*
* @return BoundingBox
* @author Maximilian Ruta <mr@xtain.net>
*/
public static function createFromCenterAndDistance(Point $center, Distance $distance)
{
$distanceInDegrees = $distance->getInGeographicDegrees() / 2;
$sw = new Point($center->getLatitude() - $distanceInDegrees, $center->getLongitude() - $distanceInDegrees);
$ne = new Point($center->getLatitude() + $distanceInDegrees, $center->getLongitude() + $distanceInDegrees);
return new BoundingBox($sw, $ne);
}
示例2: distance
/**
* @param Point $place1
* @param Point $place2
*
* @return Distance
* @author Maximilian Ruta <mr@xtain.net>
*/
public static function distance(Point $place1, Point $place2)
{
$theta = $place1->getLongitude() - $place2->getLongitude();
$dist = sin(deg2rad($place1->getLatitude())) * sin(deg2rad($place2->getLatitude())) + cos(deg2rad($place1->getLatitude())) * cos(deg2rad($place2->getLatitude())) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
return new Distance($dist);
}
示例3: getCartographicDistance
/**
* @param Point $point
* @return float
*
* thanks to http://stackoverflow.com/questions/7672759/how-to-calculate-distance-from-lat-long-in-php
*/
public function getCartographicDistance(Point $point)
{
$earthRadius = 3958.75;
$dLat = deg2rad($point->getLatitude() - $this->latitude);
$dLng = deg2rad($point->getLongitude() - $this->longitude);
$a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($this->latitude)) * cos(deg2rad($point->getLatitude())) * sin($dLng / 2) * sin($dLng / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
$dist = $earthRadius * $c;
// from miles to km
$meterConversion = 1.609344;
$geopointDistance = $dist * $meterConversion;
return round($geopointDistance, 0);
}
示例4: distanceTo
/**
* Calculate distance to another point
*
* @param Point $point
* @param string $unit
* @return float
*/
public function distanceTo(Point $point, $unit = Gps::KILOMETER)
{
$latitudeFrom = deg2rad($this->latitude);
$longitudeFrom = deg2rad($this->longitude);
$latitudeTo = deg2rad(floatval($point->getLatitude()));
$longitudeTo = deg2rad(floatval($this->getLongitude()));
$longitudeDelta = $longitudeTo - $longitudeFrom;
$longitudeDelta = $longitudeTo - $longitudeFrom;
$magnitudeA = pow(cos($latitudeTo) * sin($longitudeDelta), 2) + pow(cos($latitudeFrom) * sin($latitudeTo) - sin($latitudeFrom) * cos($latitudeTo) * cos($longitudeDelta), 2);
$magnitudeB = sin($latitudeFrom) * sin($latitudeTo) + cos($latitudeFrom) * cos($latitudeTo) * cos($longitudeDelta);
$distance = atan2(sqrt($magnitudeA), $magnitudeB) * Gps::EARTH_RADIUS;
switch ($unit) {
case Gps::KILOMETER:
return round($distance, 2);
break;
case Gps::METER:
return round($distance * 1000, 2);
break;
default:
throw new \InvalidArgumentException(sprintf('Unit "%s" is not valid', $unit));
break;
}
}
示例5: getAzimuthToPoint
public function getAzimuthToPoint(Point $point2)
{
// перевести координаты в радианы
$lat1 = $this->getLatitude() * M_PI / 180;
$lat2 = $point2->getLatitude() * M_PI / 180;
$long1 = $this->getLongitude() * M_PI / 180;
$long2 = $point2->getLongitude() * M_PI / 180;
// косинусы и синусы широт и разницы долгот
$cl1 = cos($lat1);
$cl2 = cos($lat2);
$sl1 = sin($lat1);
$sl2 = sin($lat2);
$delta = $long2 - $long1;
$cdelta = cos($delta);
$sdelta = sin($delta);
//вычисление начального азимута
$x = (double) ($cl1 * $sl2) - $sl1 * $cl2 * $cdelta;
$y = (double) $sdelta * $cl2;
$z = atan2($y, $x) * 180 / M_PI;
if ($z < 0) {
$z += 360;
}
return $z;
}
示例6: distanceTo
public function distanceTo(Point $point) : float
{
return Tools::distance($this->getLatitude(), $this->getLongitude(), $point->getLatitude(), $point->getLongitude());
}