给定坐标,我怎么得到的所有邮编codeS 10英里半径范围内?范围内、半径、坐标、邮编

由网友(天然萌女可爱范)分享简介:我有一个位置(经度和放大器;经度)。我怎样才能得到压缩codeS的是部分或全部我的位置的10英里范围内的清单?I have a location (latitude & longitude). How can I get a list of zipcodes that are either partially or...

我有一个位置(经度和放大器;经度)。我怎样才能得到压缩codeS的是部分或全部我的位置的10英里范围内的清单?

I have a location (latitude & longitude). How can I get a list of zipcodes that are either partially or fully within the 10 mile radius of my location?

该溶液可以是一个呼叫到一个公知的web服务(谷歌地图,冰地图等...)或本地数据库溶液(在客户端有SQL Server 2005),或一种算法

The solution could be a call to a well known web service (google maps, bing maps, etc...) or a local database solution (the client has sql server 2005) or an algorithm.

我见过有些similar问题,但所有的答案有pretty的很多涉及到使用SQL Server 2008地理位置功能,这是无法给我。

I have seen the somewhat similar question, but all the answers there pretty much pertain to using SQL Server 2008 geography functionality which is unavailable to me.

推荐答案

首先,你需要的所有拉链codeS及其相应的纬度和经度的数据库。在澳大利亚,只有这些几千(和信息是容易获得的),但我认为它可能是美国的一个更艰巨的任务。

Firstly, you'll need a database of all zipcodes and their corresponding latitudes and longitudes. In Australia, there are only a few thousand of these (and the information is easily available), however I assume it's probably a more difficult task in the US.

其次,鉴于你知道你在哪里,你知道你正在寻找半径,你可以看一下所有的拉链codeS下降的范围之内。简单的东西用PHP编写的将是如下:(道歉这不是在C#)

Secondly, given you know where you are, and you know the radius you are looking for, you can look up all zipcodes that fall within that radius. Something simple written in PHP would be as follows: (apologies it's not in C#)

function distanceFromTo($latitude1,$longitude1,$latitude2,$longitude2,$km){
  $latitude1  = deg2rad($latitude1);
  $longitude1 = deg2rad($longitude1);
  $latitude2  = deg2rad($latitude2);
  $longitude2 = deg2rad($longitude2);
  $delta_latitude  = $latitude2  - $latitude1;
  $delta_longitude = $longitude2 - $longitude1;
  $temp = pow(sin($delta_latitude/2.0),2) + cos($latitude1) * cos($latitude2) * pow(sin($delta_longitude/2.0),2);
  $earth_radius = 3956;
  $distance = $earth_radius * 2 * atan2(sqrt($temp),sqrt(1-$temp));
  if ($km)
    $distance = $distance * 1.609344;
  return $distance;
}
阅读全文

相关推荐

最新文章