PHP计算百度地图两个GPS坐标之间距离的方法
这篇文章主要介绍了PHP计算百度地图两个GPS坐标之间距离的方法,是针对百度地图接口开发的典型应用,需要的朋友可以参考下
本文实例讲述了PHP计算百度地图两个GPS坐标之间距离的方法。分享给大家供大家参考。
具体实现方法如下:
复制代码 代码如下:
/**
* 计算两个坐标之间的距离(米)
* @param float $fP1Lat 起点(纬度)
* @param float $fP1Lon 起点(经度)
* @param float $fP2Lat 终点(纬度)
* @param float $fP2Lon 终点(经度)
* @return int
*/
function distanceBetween($fP1Lat, $fP1Lon, $fP2Lat, $fP2Lon){
$fEARTH_RADIUS = 6378137;
//角度换算成弧度
$fRadLon1 = deg2rad($fP1Lon);
$fRadLon2 = deg2rad($fP2Lon);
$fRadLat1 = deg2rad($fP1Lat);
$fRadLat2 = deg2rad($fP2Lat);
//计算经纬度的差值
$fD1 = abs($fRadLat1 - $fRadLat2);
$fD2 = abs($fRadLon1 - $fRadLon2);
//距离计算
$fP = pow(sin($fD1/2), 2) +
cos($fRadLat1) * cos($fRadLat2) * pow(sin($fD2/2), 2);
return intval($fEARTH_RADIUS * 2 * asin(sqrt($fP)) + 0.5);
}
/**
* 百度坐标系转换成标准GPS坐系
* @param float $lnglat 坐标(如:106.426, 29.553404)
* @return string 转换后的标准GPS值:
*/
function BD09LLtoWGS84($fLng, $fLat){ // 经度,纬度
$lnglat = explode(',', $lnglat);
list($x,$y) = $lnglat;
$Baidu_Server = "http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x={$x}&y={$y}";
$result = @file_get_contents($Baidu_Server);
$json = json_decode($result);
if($json->error == 0){
$bx = base64_decode($json->x);
$by = base64_decode($json->y);
$GPS_x = 2 * $x - $bx;
$GPS_y = 2 * $y - $by;
return $GPS_x.','.$GPS_y;//经度,纬度
}else
return $lnglat;
}
希望本文所述对大家的php程序设计有所帮助。
,
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide
