【问题标题】:Get a list of zip codes near a latitude/longitude获取纬度/经度附近的邮政编码列表
【发布时间】:2012-04-20 13:26:30
【问题描述】:

我有一个 android 应用程序可以找到您当前的位置,但我需要确定哪些邮政编码在当前位置的 20 英里范围内。找到这些信息的最佳方式是什么?是否有公共 API 或 Web 服务?我可以输入纬度/经度或邮政编码。

【问题讨论】:

标签: java android


【解决方案1】:

我将从使用Haversine 公式开始。使用从中获得的结果来查找相对于该半径的邮政编码。

import com.google.android.maps.GeoPoint;  

public class DistanceCalculator {  

   private double Radius;  

   // R = earth's radius (mean radius = 6,371km)  
   // Constructor  
   DistanceCalculator(double R) {  
      Radius = R;  
   }  

   public double CalculationByDistance(GeoPoint StartP, GeoPoint EndP) {  
      double lat1 = StartP.getLatitudeE6()/1E6;  
      double lat2 = EndP.getLatitudeE6()/1E6;  
      double lon1 = StartP.getLongitudeE6()/1E6;  
      double lon2 = EndP.getLongitudeE6()/1E6;  
      double dLat = Math.toRadians(lat2-lat1);  
      double dLon = Math.toRadians(lon2-lon1);  
      double a = Math.sin(dLat/2) * Math.sin(dLat/2) +  
         Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *  
         Math.sin(dLon/2) * Math.sin(dLon/2);  
      double c = 2 * Math.asin(Math.sqrt(a));  
      return Radius * c;  
   }  
}  

【讨论】:

    【解决方案2】:

    您必须使用反向地理编码器,例如:

    http://www.geonames.org/

    【讨论】:

      【解决方案3】:

      据我所知,目前还没有这方面的 api,但您可以使用邮政编码数据库 http://zips.sourceforge.net/ 创建您自己的数据库来使用

      【讨论】:

        猜你喜欢
        • 2012-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多