Reputation: 9171
I have a method with body like this:
Address address = new Geocoder(context).getFromLocation(latitude, longitude, 5).get(0);
return address.getThoroughfare() + ", " + address.getSubThoroughfare() + ", " + address.getSubLocality();
When I print the result, the value of address.getSubLocality()
shows a string in Japanese.
Why this happnes?
And how can I fix this?
Thank you!
EDIT
My full example project:
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);
}
}
}
Upvotes: 3
Views: 1691
Reputation: 22342
It returns that way because that's how it's labeled in Google Maps. The Japanese characters you see(アウファヴィーレ
) are the representation for Alphaville, a development company in that area.
Why someone labeled it in Japanese, I don't know. There's not much you can do about it, though. Other locations nearby aren't labeled this way.
Upvotes: 2
Reputation: 12933
The constructor of the Geocoder class takes a Locale Object as parameter. With this you can have the output in any supported language. If you don't set a explicit local, as in your snippet, Locale.getDefault() will be used by default.
Address address = new Geocoder(context, Locale.ENGLISH)
.getFromLocation(latitude, longitude, 5).get(0);
Upvotes: -1