欧卡2中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

需要三步,才能开始

只需两步,慢速开始

玩欧卡就用莱仕达V99方向盘欧卡2入门方向盘选莱仕达V9莱仕达折叠便携游戏方向盘支架欢迎地图Mod入驻
查看: 8016|回复: 4
收起左侧

测试PHP语言

[复制链接]
zxw445 发表于 2015-7-27 23:29 | 显示全部楼层 |阅读模式
function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
    $theta = $longitude1 - $longitude2;
    $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $miles = acos($miles);
    $miles = rad2deg($miles);
    $miles = $miles * 60 * 1.1515;
    $feet = $miles * 5280;
    $yards = $feet / 3;
    $kilometers = $miles * 1.609344;
    $meters = $kilometers * 1000;
    return compact('miles','feet','yards','kilometers','meters'); 
}

$point1 = array('lat' => 40.770623, 'long' => -73.964367);
$point2 = array('lat' => 40.758224, 'long' => -73.917404);
$distance = getDistanceBetweenPointsNew($point1['lat'], $point1['long'], $point2['lat'], $point2['long']);
foreach ($distance as $unit => $value) {
    echo $unit.': '.number_format($value,4).'
';
}

The example returns the following:

miles: 2.6025
feet: 13,741.4350
yards: 4,580.4783
kilometers: 4.1884
meters: 4,188.3894
 楼主| zxw445 发表于 2015-7-27 23:30 | 显示全部楼层
{:1_421:} 问题多多
回复 打印

使用道具 举报

 楼主| zxw445 发表于 2015-7-27 23:30 | 显示全部楼层
回复 打印

使用道具 举报

知行 发表于 2015-7-28 18:08 | 显示全部楼层

效果:
<?php
/**
 * graphviz api
 *
 * $Id api.php  [email]i@annhe.net[/email] 2015-6-8 $
 **/
$host = $_SERVER['HTTP_HOST'];
$siteurl = "http://" . $host . "/gv/"; 
$cht = "dot";
$chl = "graph {fontname=\"SimSun\";node[shape=box];a[label=\"nothing to do~\"];}";
$error = "error.png";
$engine = array("dot", "neato", "fdp", "sfdp", "twopi", "circo");
$imgtype = "png"; 
$imgtype_arr = array("png", "gif", "jpeg");
 
if(isset($_GET['cht'])) {
        $cht = $_GET['cht'];
        $arr = explode(':', $cht);
        if(!array_key_exists("1", $arr)) {
                $cht = "dot";
        } else {
                $cht = $arr['1'];
        }
        if(!in_array($cht, $engine)) {
                $cht = "dot";
        }
}
if(isset($_GET['chl'])) {
        $chl = $_GET['chl'];
}
 
if(isset($_GET['chof'])) {
        $imgtype = $_GET['chof'];
        if(!in_array($imgtype, $imgtype_arr)) {
                $imgtype = "png";
        }
}
 
$gvname = md5($chl) . $cht;
$gvpath = "./gv/" . $gvname . ".gv";
$imgpath = "img/" . $gvname . "." .  $imgtype;
 
 
$file = fopen("$gvpath", "w");
$encode = mb_detect_encoding($chl, array("ASCII","UTF-8","GB2312", "GBK", "EUC-CN"));
 
if($encode != "UTF-8") { 
        $chl = iconv("$encode", "UTF-8", $chl);
}
$chl = str_replace(">", ">", $chl);
$chl = str_replace("<", "<", $chl);
$chl = str_replace(""", "\"", $chl);
fwrite($file, "$chl");
fclose($file);
if(!file_exists($imgpath)) {
        exec("$cht -T$imgtype $gvpath -o $imgpath",$out, $ret);
        if($ret != 0) {
                $imgpath = $error;                
                $imgtype = "png";
        }
}
 
$imgstrout = "image$imgtype(imagecreatefrom$imgtype('$imgpath'));";
header("Content-Type: image/$imgtype; charset=UTF-8");
eval($imgstrout);
?>
知行 发表于 2015-7-28 18:12 | 显示全部楼层
function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
    $theta = $longitude1 - $longitude2;
    $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $miles = acos($miles);
    $miles = rad2deg($miles);
    $miles = $miles * 60 * 1.1515;
    $feet = $miles * 5280;
    $yards = $feet / 3;
    $kilometers = $miles * 1.609344;
    $meters = $kilometers * 1000;
    return compact('miles','feet','yards','kilometers','meters'); 
}

$point1 = array('lat' => 40.770623, 'long' => -73.964367);
$point2 = array('lat' => 40.758224, 'long' => -73.917404);
$distance = getDistanceBetweenPointsNew($point1['lat'], $point1['long'], $point2['lat'], $point2['long']);
foreach ($distance as $unit => $value) {
    echo $unit.': '.number_format($value,4).'
';
}

The example returns the following:

miles: 2.6025
feet: 13,741.4350
yards: 4,580.4783
kilometers: 4.1884
meters: 4,188.3894

联系我们|手机版|欧卡2中国 ( 湘ICP备11020288号-1 )

GMT+8, 2024-11-25 12:26 , Processed in 0.046440 second(s), 8 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表