Android API 有Location.distanceBetween()
,它接受两个纬度/经度值并返回以米为单位的距离。有没有一种方法可以让我只有一个邮政编码才能达到这个距离?
问问题
1094 次
1 回答
1
You may want to use Android's Geocoder API. Something like this should work:
String locationName = zipCode + ", " + countryName;
Geocoder geoCoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> address = geoCoder.getFromLocationName(locationName, 1);
double latitude = address.get(0).getLatitude();
double longitude = address.get(0).getLongitude();
Location.distanceBetween(...);
} catch (IOException e) {
e.printStackTrace();
}
You need to include the country's name because of this: Get latitude and longitude based on zip using Geocoder class in Android
于 2013-11-11T23:31:37.787 回答