给定GPS的地理位置,如何在给定的x米半径内找到纬度和经度

时间:2012-03-01 07:59:13

标签: java android geolocation latitude-longitude

我正在编写一个Android应用程序,我想知道是否有任何API有助于插入从GPS获得的纬度和经度并插入半径R,以非常高的精度找到新的纬度和经度。优选地是Java代码。 所以说例如当前位置是curX和curY 现在在这个位置的200米半径范围内可以是maxX和maxY。因此,如果我有一个条目列表,我将只打印最大范围内的条目。所以为了比较是正确的,精度应该很高。有没有API可以做到这一点?任何公式? (在Java中)

So the function is
findNewLatitude(curLat,curLong,oldList,radius)
{
  do bla bla bla; //Find a newList with respect to current Geo points on MAP  and      considering the radius
}

output: newList such that distance between (lat,long) in newList and 
(curLat,curLong) is  equal to radius

3 个答案:

答案 0 :(得分:1)

试试这个:

Geocoder coder = new Geocoder(this);
List<Address> address;

try {
    address = coder.getFromLocationName(strAddress,5);
    if (address == null) {
        return null;
    }
    Address location = address.get(0);
    location.getLatitude();
    location.getLongitude();

    p1 = new GeoPoint((int) (location.getLatitude() * 1E6),
                      (int) (location.getLongitude() * 1E6));

     return p1;
}

请参阅此回答How to get city name from latitude and longitude coordinates in Google Maps?

How to change 1 meter to pixel distance?

答案 1 :(得分:0)

我猜你正在寻找这种方法:

http://developer.android.com/reference/android/location/Location.html#distanceTo%28android.location.Location%29

这将计算2个给定位置之间的距离

答案 2 :(得分:0)

List<Location> filter(Location current, List<Location> locations, int radius) {
    List<Location> results = new ArrayList<Location>();
    for (Location loc : locations) {
        if (current.distanceTo(loc) <= radius) {
            results.add(loc);
        }
    }
    return results;
}