Java 地理编码器不';行不通
我对Java 地理编码器不';行不通,java,android,android-activity,geocoding,street-address,Java,Android,Android Activity,Geocoding,Street Address,我对Geocoder有问题。我做了一些研究,但没有找到问题的答案 这是我的代码: public String getAddress(double lat,double lon){ TextView tv=(TextView)findViewById(R.id.textView3); TextView tv2=(TextView)findViewById(R.id.textView4); tv.setText(lat+","+lon);///Checks did i received
Geocoder
有问题。我做了一些研究,但没有找到问题的答案
这是我的代码:
public String getAddress(double lat,double lon){
TextView tv=(TextView)findViewById(R.id.textView3);
TextView tv2=(TextView)findViewById(R.id.textView4);
tv.setText(lat+","+lon);///Checks did i received lat and lon (Yes)
String ret = "";
try {
Geocoder geocoder = new Geocoder(this.getApplicationContext(), Locale.getDefault());
List<Address>addresses = geocoder.getFromLocation(lat, lon, 1);
if (addresses.isEmpty()) {
ret = "No Address returned!";
} else {
ret = addresses.get(0).getCountryName() + ""+ >addresses.get(0).getFeatureName();
}
} catch (IOException e) {
ret="We don't know your address...";
e.printStackTrace();
}
return ret;
}
公共字符串getAddress(双lat,双lon){
TextView tv=(TextView)findViewById(R.id.textView3);
TextView tv2=(TextView)findViewById(R.id.textView4);
tv.setText(lat+,“+lon);///检查我是否收到lat和lon(是)
字符串ret=“”;
试一试{
Geocoder Geocoder=新的Geocoder(this.getApplicationContext(),Locale.getDefault());
Listaddresses=geocoder.getFromLocation(lat,lon,1);
if(addresses.isEmpty()){
ret=“没有返回地址!”;
}否则{
ret=addresses.get(0.getCountryName()+“”++>addresses.get(0.getFeatureName();
}
}捕获(IOE异常){
ret=“我们不知道您的地址…”;
e、 printStackTrace();
}
返回ret;
}
我试图在模拟器和手机上运行我的应用程序,但它不起作用。每次它告诉我“我们不知道……”
我有权限访问互联网、精细位置和粗略位置。您是否在日志中检查是否存在与此相关的警告?如果设备api级别低于jellybean,则可能需要重新启动设备。您是否可以从引发的IOException发布堆栈跟踪?E/sw29 TextView(11517):getCurrentProcessName currProcessID=11517,E/sw29 TextView(11517):currProcessName=com.rServices.homethx,问题已解决!当我重新启动它的工作非常好。thx:)