如何计算两个城市的方向?
计算两个纬度 - 经度到度和宽度的代码
function getlocationcoords($lat, $lon)
{
//image amp height and width;
$height = 1096;
$width = 543;
$x = (($lon + 180) * ($width / 360));
$y = ((($lat * -1) + 90) * ($height / 180)) - 7;
return array("x" => round($x), "y" => round($y));
}
$latlongfrom = getlocationcoords($cityfrom->latitude, $cityfrom->longitude);
$latlongto = getlocationcoords($cityto->latitude, $cityto->longitude);
$width = hypot($latlongto['y'] - $latlongfrom['y'], $latlongto['x'] - $latlongfrom['x']);
$deg = atan2($latlongto['y'] - $latlongto['y'], $latlongfrom['x'] - $latlongfrom['x']) * 180 / M_PI;
<div class="col-md-12 col-sm-12 col-xs-12" style=" overflow: hidden;">
<img id="worldmap" src="<?php echo base_url('uploads/worldmap5.png'); ?>" alt="worldmap" title="World map">
<div class="line" style="width: <?php echo $width ?>px;left: <?php echo $latlongfrom['x'] ?>px; top: <?php echo $latlongfrom['y'] ?>px; transform: rotate(<?php echo $deg ?>rad);border-bottom: 5px solid rgb(214, 0, 4); border-top-color: rgb(214, 0, 4); border-right-color: rgb(214, 0, 4); border-left-color: rgb(214, 0, 4); position: absolute; z-index: 1001;"></div>
;;
</div>