gpt4 book ai didi

php - 如何最好地计算两个城市(加拿大)之间的距离?

转载 作者:行者123 更新时间:2023-11-29 17:29:52 29 4
gpt4 key购买 nike

我有一个客户要我计算城市之间的距离(以英里为单位)。我正在用 PHP、javascript 做项目,我一直在阅读一些 long/lat 数据库,但仍然无法找到从哪里开始以及如何使用它。有没有我可以通过传递两个城市名称来查询的网络服务,它可以返回以英里或公里为单位的距离?请帮忙

最佳答案

http://code.google.com/apis/maps/documentation/javascript/geometry.html#Distance

Distance and Area FunctionsThe distance between two points is the length of the shortest path between them. This shortest path is called a geodesic. On a sphere all geodesics are segments of a great circle. To compute this distance, call computeDistanceBetween(), passing it two LatLng objects.

You may instead use computeLength() to calculate the length of a given path if you have several locations.

To compute the area of polygonal area, call computeArea(), passing the array of LatLng objects defining a closed loop.

如果您不想维护一个 GEO 数据库来维护某个地方/城市的纬度/经度,那么您还可以使用 Google API 检索“地址”的坐标: http://code.google.com/apis/maps/documentation/javascript/services.html#GeocodingRequests

如果您不是谷歌粉丝,另一种选择是使用在 Javascript 中实现的大圆计算器的变体:

https://gist.github.com/missinglink/ab7c8b9b8699622539986373e6237fd4

https://www.edwilliams.org/gccalc.htm

关于php - 如何最好地计算两个城市(加拿大)之间的距离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5676821/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com