用户位置与用户输入的位置之间的距离

时间:2014-06-10 12:16:00

标签: android location distance

我想找到用户位置和他进入的地方之间的距离。输入的位置将是一个地址。使用位置类我可以找到用户位置的坐标,但是如何找到输入位置的坐标。无法在Google Maps API中找到它。

1 个答案:

答案 0 :(得分:2)

您可以从以下地址检索位置:

public GeoPoint getLocationFromAddress(String strAddress) {
    Geocoder coder = new Geocoder(this);
    List<Address> address = new ArrayList<Address>();

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

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

        return p1;
    } catch (Exception e) {}

    return null;
}

距离使用distanceBetween

相关问题