Table of Contents
PHP根据两点间的经纬度计算距离,php两点经纬度计算
php计算两个经纬度之间的距离问题,指导
如果知道两点的经纬度 怎算两点之间的距离
Home php教程 php手册 PHP根据两点间的经纬度计算距离,php两点经纬度计算

PHP根据两点间的经纬度计算距离,php两点经纬度计算

Jun 13, 2016 am 09:22 AM
Latitude and longitude distance

PHP根据两点间的经纬度计算距离,php两点经纬度计算

这是一个不错的示例,直接贴代码,首先要知道纬度值、经度值

/** 
* @desc 根据两点间的经纬度计算距离 
* @param float $lat 纬度值 
* @param float $lng 经度值 
*/ 
function getDistance($lat1, $lng1, $lat2, $lng2) 
{ 
$earthRadius = 6367000; //approximate radius of earth in meters 

/* 
Convert these degrees to radians 
to work with the formula 
*/ 

$lat1 = ($lat1 * pi() ) / 180; 
$lng1 = ($lng1 * pi() ) / 180; 

$lat2 = ($lat2 * pi() ) / 180; 
$lng2 = ($lng2 * pi() ) / 180; 

/* 
Using the 
Haversine formula 

http://en.wikipedia.org/wiki/Haversine_formula 

calculate the distance 
*/ 

$calcLongitude = $lng2 - $lng1; 
$calcLatitude = $lat2 - $lat1; 
$stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2); 
$stepTwo = 2 * asin(min(1, sqrt($stepOne))); 
$calculatedDistance = $earthRadius * $stepTwo; 

return round($calculatedDistance); 
} 
Copy after login

php计算两个经纬度之间的距离问题,指导

不会算这个东西,不过看代码发现你的代码里有些问题
第一、两点间的直线距离平方:$len算完了后面没有用到,也没有return, 完全就没用了
第二、输入相同的经纬度,结果居然不是0,而且还是个很大的数,所以应该是有问题的

你可以百度一下“php 按经纬度算两点间距离”,有不少现成的代码
我看这个介绍的比较详细,还有代码,你可以看看
blog.csdn.net/...963740
 

如果知道两点的经纬度 怎算两点之间的距离

同纬度不同经度 (赤道除外)
h X 111 X COSD=G (h=两地经度差 D=当地的地理纬度 G=实际距离)

跨纬度的需要构造个三角
比如说AB两点不同经纬度(A经B纬)
那就先算出与A点共线的那条纬度B'的距离,在算A到B'的距离,在用勾股定理就可以得出

简单的说可用以下通用公式:
地球上任两点间距离公式:
地球上任两点,其经度分别为A1、A2(E正,W负),纬度分别为B1、B2(N正,S负)。
令A0=(A1-A2)÷2,B0=(BI-B2)÷2
f=√sinB0×sinB0+cosB1×cosB2×sinA0×sinA0


1、两点间空间直线距离=2fR
2、两点间最小球面距离=arcsinf÷90°×∏R(角度)
3、两点间最小球面距离=arcsinf×2R(弧度)

说明:E、W、N、S=东西南北;R=地球半径;√=根号;∏=圆周率。
代入公式自己算吧
 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

C program to calculate distance between three points in 3D space C program to calculate distance between three points in 3D space Aug 29, 2023 pm 12:41 PM

Given a three-dimensional plane and therefore three coordinates, the task is to find the distance between the given points and display the result. On the three-dimensional plane, there are three coordinate axes, the coordinates of the x-axis are (x1, y1, z1), the coordinates of the y-axis are (x2, y2, z2), and the coordinates of the z-axis are (x3, y3, z). There is a direct formula for calculating the distance between them as follows $$\sqrt{\lgroupx2-x1\rgroup^{2}+\lgroupy2-y1\rgroup^{2}+\lgroupz2-z1\rgroup^{2 }}$$The following is an illustration showing three different coordinate axes and their coordinates. The method used below is as follows −Input coordinates (x1,

Numerical distance based on machine learning: the distance between points in space Numerical distance based on machine learning: the distance between points in space Apr 11, 2023 pm 11:40 PM

This article is reprinted from the WeChat public account "Living in the Information Age". The author lives in the information age. To reprint this article, please contact the Living in the Information Age public account. In machine learning, a basic concept is how to judge the difference between two samples, so that the similarity and category information between the two samples can be evaluated. The measure to judge this similarity is the distance between two samples in the feature space. There are many measurement methods based on different data characteristics. Generally speaking, for two data samples x, y, define a function d(x, y). If it is defined as the distance between the two samples, then d(x, y) needs to satisfy the following basic properties : Non-negativity: d(x, y)>=0 Identity: d(x, y)=0 ⇔ x=y pair

How to enable and use screen distance on iOS 17 How to enable and use screen distance on iOS 17 Jun 29, 2023 pm 01:37 PM

At its annual developers conference, Apple unveiled the next generation of operating systems to power its suite of devices. As usual, iOS 17 is at the center of all the major changes, with features like live voicemail, message transcription, live stickers, standby mode, full-screen live activities, interactive widgets, and more. One of the features that stands out among these new additions is Screen Distance. This is a health-centric feature focused on preventing eye strain and myopia on your iPhone screen. In this article, we will explain what screen distance is and how to enable it in iOS17. What is screen distance on iOS17? As part of the new health features introduced in iOS 17, Apple is offering a screen distance feature to help users anticipate

iOS 17: How to enable and use screen distance on iPhone iOS 17: How to enable and use screen distance on iPhone Sep 21, 2023 pm 02:25 PM

What is the screen distance feature in iOS17 update? Apple provides a screen distance function on the iPhone to help users prevent eye fatigue and the risk of myopia. The feature (available on iOS 17 or later) will use the iPhone's TrueDepth camera (the same camera that also helps FaceID) to measure the distance between the face and the phone. If Screen Distance detects that you are holding your iPhone closer than 12 inches or 30 centimeters for an extended period of time, it will prompt you to maintain distance from the iPhone screen. When your device detects that it is less than 12 inches from your face, you will see the "iPhone too close" message on the screen and advise that you should keep your distance to protect your vision. Only if you place the device further

How to view longitude and latitude on Baidu Maps How to view longitude and latitude How to view longitude and latitude on Baidu Maps How to view longitude and latitude Mar 12, 2024 pm 12:10 PM

When we use this platform, we all know that every location has coordinates. I believe that students who have studied geography will know what the longitude and latitude coordinates are. The above functions can be said to be very powerful. Not only can you locate some of your locations in real time, but it can also let you know what the current longitude and latitude are. That is to say, we can all check the longitude and latitude coordinates of any location on the map. In this way, we can know the corresponding specific locations more accurately, but the majority of users who don’t know are still viewing it, so in order to give you a better understanding of it, let’s join the editor now Take a look, I believe you won’t miss it, come and take a look.

How to check latitude and longitude on Google Maps How to check latitude and longitude on Google Maps Mar 24, 2024 pm 05:31 PM

You can check the latitude and longitude on Google Maps, but how do you check the latitude and longitude? Users click on the information of a location, and then click to view more, to view the specific longitude and latitude information. This introduction to the method of checking longitude and latitude can tell you the specific content. The following is the detailed method, so take a look. How to check latitude and longitude on Google Maps A: Click on the location and select to view detailed information. Detailed introduction: Mobile version: 1. First, go to the progress map and select a location you want to view. 2. Click the View All button inside. 3. You can see the detailed latitude and longitude. PC version: 1. First enter the Google Maps website. https://www.google.cn2. Right-click to view the desired location and click What's here.

How to use Java code to display the latitude and longitude of the current location on Baidu Map? How to use Java code to display the latitude and longitude of the current location on Baidu Map? Aug 06, 2023 pm 08:48 PM

How to use Java code to display the latitude and longitude of the current location on Baidu Map? Baidu Maps is a very popular map application that is often used when developing geolocation-related applications. This article will introduce how to use Java code to display the longitude and latitude of the current location on Baidu Map. First, we need to prepare a Baidu developer account and create an application to obtain the API key. After registering an account and logging in on the Baidu developer website, we can create an application in the console and obtain an API key for accessing

The reason why the working distance of UWB base stations continues to increase - IOTE Internet of Things Exhibition The reason why the working distance of UWB base stations continues to increase - IOTE Internet of Things Exhibition Nov 27, 2023 pm 01:21 PM

An interesting trend has emerged for UWB technology in the industry application market: the transmission distance of base stations is gradually increasing. A typical scene is a tunnel or a mine. The characteristic of this scene is that the space is linear and there are not many obstructions in the middle. UWB Base stations are also laid out in straight lines. The farther the working distance of the base station, the fewer the number of base stations required for the project, and the lower the project cost. Under market competition, the working distance of UWB base stations on the market is getting farther and farther. The working distance of the base station has increased from tens of thousands in the early days. meters, expanded to 100m, 200m, 500m, 1000m, 2000m or even further. This article will not discuss the business logic behind this too much. Why do UWB base stations work farther and farther away? There are two key components, one is the antenna, and the other

See all articles