【问题标题】:Distance calculation between two zip codes(post codes) in php?php中两个邮政编码(邮政编码)之间的距离计算?
【发布时间】:2010-08-25 10:30:02
【问题描述】:

我正在开发一个需要计算两个邮政编码之间距离的网站。我有一个数据库表,其中包含邮政编码及其相关的纬度和经度。我利用它来计算两个地方之间的距离。

但我有一个问题,这给了我直线距离而不是行驶距离 - 我怎样才能找到它?

我正在使用以下代码

  $lat1 = $this->deg_to_rad($lat1);
   $lon1 = $this->deg_to_rad($lon1);
   $lat2 = $this->deg_to_rad($lat2);
   $lon2 = $this->deg_to_rad($lon2);

   $delta_lat = $lat2 - $lat1;
   $delta_lon = $lon2 - $lon1;

   $temp = pow(sin($delta_lat/2.0),2) + cos($lat1) * cos($lat2) * pow(sin($delta_lon/2.0),2);

   $distance = 3956 * 2 * atan2(sqrt($temp),sqrt(1-$temp));

【问题讨论】:

  • 当说“实际距离”时,您是指“大圈距离”、“行驶距离”还是其他什么意思?在这种情况下,您无法称其为“一个真实的距离”(有几种有效的可能性),您需要更具体。
  • 嗨,我的意思是行驶距离。因为有时直线距离和行驶距离之间存在很大差异。

标签: php distance zipcode


【解决方案1】:

您可以在此处静默调用 Google Maps GDirection()。它不仅为您提供路线,还为您提供实际距离,但这是 javascript 解决方案,将这些数据提供给 php 的唯一方法是捕获接收到的距离并通过 AJAX 发送到 php。

【讨论】:

  • 您好,我会尽力执行您的建议。谢谢你。
猜你喜欢
  • 1970-01-01
  • 2014-06-09
  • 2017-10-25
  • 1970-01-01
  • 1970-01-01
  • 2014-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多