2012-04-20 110 views
1

我有一个安卓应用程序可以查找您当前的位置,但我需要弄清楚哪些邮政编码位于20英里的当前位置。什么是找到这些信息的最佳方式?是否有公共API或Web服务?我可以输入纬度/经度或邮政编码。获取纬度/经度附近的邮政编码列表

+0

上班这实际上是反向地址解析的问题,这是将经纬度转换为可读地址的过程。有一个Google API https://developers.google.com/maps/documentation/geocoding/这应该有助于开始。 – twain249 2012-04-20 13:30:58

回答

0

我会使用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; 
    } 
} 
0

有对此没有API,作为我,只要我知道,但你可以使用邮编数据基础http://zips.sourceforge.net/来创建自己的数据库与

相关问题