我正在使用Geocoder
类来获取用户在EditText
中输入的字符串地址的纬度和经度。
有趣的是,它可以返回“q”、“qq”、“n”、“N”等查询的结果。有没有办法使其更好(验证或其他服务)?
if (!s.toString().isEmpty()) {
try {
List<Address> addresses = geocoder.getFromLocationName(s.toString(), 4);
if (addresses.size() > 0) {
Address userAddress = addresses.get(0);
double latitude = userAddress.getLatitude();
double longitude = userAddress.getLongitude();
mRestaurantLatLng = new LatLng(latitude, longitude);
if (userAddress != null) {
mPin.setVisibility(View.VISIBLE);
} else {
mPin.setVisibility(View.GONE);
mRestaurantLatLng = null;
}
} else {
mPin.setVisibility(View.GONE);
mRestaurantLatLng = null;
}
} catch (Exception e) {
e.printStackTrace();
}