0
我想查找用户位置与他输入的位置之间的距离。输入的位置将是一个地址。使用位置类我可以找到用户位置的坐标,但是如何找到输入位置的坐标。无法在Google Maps API中找到。用户位置与用户输入的位置之间的距离
我想查找用户位置与他输入的位置之间的距离。输入的位置将是一个地址。使用位置类我可以找到用户位置的坐标,但是如何找到输入位置的坐标。无法在Google Maps API中找到。用户位置与用户输入的位置之间的距离
可以从这样一个地址检索位置:
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。