Android 如何根据EditText值查找用户位置
我正在尝试从Android 如何根据EditText值查找用户位置,android,android-location,Android,Android Location,我正在尝试从EditText获取用户的城市,然后检查它是否有效。如果有一点输入错误,那么我想在EditText上更正它,然后将其显示给用户 我已经搜索了很长一段时间,但我得到的是获得用户当前位置,然后根据lat和long值获取其位置。但我不想这么做 这就是我现在正在做的,但我不想这样做 userDataFrag.loc.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
EditText
获取用户的城市,然后检查它是否有效。如果有一点输入错误,那么我想在EditText
上更正它,然后将其显示给用户
我已经搜索了很长一段时间,但我得到的是获得用户当前位置,然后根据lat和long值获取其位置。但我不想这么做
这就是我现在正在做的,但我不想这样做
userDataFrag.loc.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
@Override
public void onStatusChanged(String provider,
int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
userLat = location.getLatitude();
userLong = location.getLongitude();
Geocoder geocoder = new Geocoder(getActivity(),
Locale.getDefault());
List<Address> addresses;
try {
addresses = geocoder.getFromLocation(userLat,
userLong, 1);
CityName = addresses.get(0).getAddressLine(0);
StateName = addresses.get(0).getAddressLine(1);
CountryName = addresses.get(0).getAddressLine(2);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
userDataFrag.loc.requestLocationUpdates(
LocationManager.GPS_提供程序,0,0,新LocationListener(){
@凌驾
公共无效onStatusChanged(字符串提供程序,
int状态,捆绑附加){
//TODO自动生成的方法存根
}
@凌驾
公共无效onProviderEnabled(字符串提供程序){
//TODO自动生成的方法存根
}
@凌驾
公共无效onProviderDisabled(字符串提供程序){
//TODO自动生成的方法存根
}
@凌驾
已更改位置上的公共无效(位置){
//TODO自动生成的方法存根
userLat=location.getLatitude();
userLong=location.getLongitude();
Geocoder Geocoder=新的地理编码器(getActivity(),
Locale.getDefault());
列出地址;
试一试{
地址=geocoder.getFromLocation(userLat,
userLong,1);
CityName=addresses.get(0).getAddressLine(0);
StateName=addresses.get(0).getAddressLine(1);
CountryName=addresses.get(0).getAddressLine(2);
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
});
有谁能给我一个更好的方法吗?用户可以输入的城市集是什么?可以是世界上任何一个城市