我试图让驾驶使用谷歌地图API两点之间的距离.现在,我有直接距离的代码:
这个函数得到lat和lng:
function get_coordinates($city, $street, $province)
{
$address = urlencode($city.','.$street.','.$province);
$url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=Poland";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
$return = array('lat' => $response_a->results[0]->geometry->location->lat, 'long' => $long = $response_a->results[0]->geometry->location->lng);
return $return;
}
Run Code Online (Sandbox Code Playgroud)
此函数根据lat&lng计算两点之间的距离:
function getDistanceBetweenPoints($lat1, $lon1, $lat2, $lon2) {
$theta = $lon1 - $lon2;
$miles = (sin(deg2rad($lat1)) * sin(deg2rad($lat2))) + (cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)));
$miles = acos($miles);
$miles …Run Code Online (Sandbox Code Playgroud) 我想检测用户是否在同一会话中打开了多个窗口或标签,如果他这样做了 - 我想在屏幕上打印一个特殊信息.
这个限制只应该在一个特殊的URL中,所以如果用户打开两个带有URL的标签/窗口:http://page.com/limite.htm - 我想打印特殊信息.当用户打开两个带有网址的窗口/标签时:http://page.com/limite.htm和http://page.com/index.htm - 一切正常,我不会显示任何信息.
可能吗?谢谢.
我有这些字符串:
$string = 'Tester,';
Run Code Online (Sandbox Code Playgroud)
最后我想得到:
"测试"
我试过这样的:
$string = rtrim($string, array(',', '.'));
Run Code Online (Sandbox Code Playgroud)
但是rtrim()的第二个参数不能是一个数组.
如何从字符串的末尾删除所有不是字母或数字的东西?
谢谢.