给定坐标,我怎么得到的所有邮编codeS 10英里半径范围内? [英] Given coordinates, how do I get all the Zip Codes within a 10 mile radius?

查看:242
本文介绍了给定坐标,我怎么得到的所有邮编codeS 10英里半径范围内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个位置(经度和放大器;经度)。我怎样才能得到压缩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.

我见过有些<一href="http://stackoverflow.com/questions/3919878/how-to-return-all-instances-within-mile-radius-of-a-list-of-zip$c$cs">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;
}

这篇关于给定坐标,我怎么得到的所有邮编codeS 10英里半径范围内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆