我有一个这样的方法:
Address address = new Geocoder(context).getFromLocation(latitude, longitude, 5).get(0);
return address.getThoroughfare() + ", " + address.getSubThoroughfare() + ", " + address.getSubLocality();
当我打印结果时, 的值address.getSubLocality()
显示一个日语字符串。
为什么会这样?
我该如何解决这个问题?
谢谢!
编辑
我的完整示例项目:
public class MainActivity extends Activity implements View.OnClickListener {
EditText ed1, ed2;
TextView tv1;
Button bt1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = (EditText) findViewById(R.id.ed1);
ed2 = (EditText) findViewById(R.id.ed2);
tv1 = (TextView) findViewById(R.id.tv1);
bt1 = (Button) findViewById(R.id.bt1);
ed1.setText("-23.50282");
ed2.setText("-46.84905");
bt1.setOnClickListener(this);
}
public static String getAddressFromLocation(Context context, Double latitude, Double longitude) throws IOException {
Address address = new Geocoder(context, Locale.ENGLISH).getFromLocation(latitude, longitude, 5).get(0);
return address.getThoroughfare() + ", " + address.getSubThoroughfare() + ", " + address.getSubLocality() + " - " + address.getAdminArea();
}
@Override
public void onClick(View v) {
String address = "Street";
if (v.getId() == R.id.bt1) {
try {
address = getAddressFromLocation(this, Double.parseDouble(ed1.getText().toString()), Double.parseDouble(ed2.getText().toString()));
} catch (IOException e) {
e.printStackTrace();
}
tv1.setText(address);
}
}
}