当我按国家/地区名称搜索时,它运行得很好,但当我搜索城市或地点时,应用程序崩溃了。这是代码:
EditText location_tf = (EditText)findViewById(R.id.TFaddress);
String location = location_tf.getText().toString();
//Toast.makeText(this, location, Toast.LENGTH_SHORT).show();
Geocoder gc = new Geocoder(this);
List<Address> list = gc.getFromLocationName(location, 1);
Address add = list.get(0);
String locality = add.getLocality();
Toast.makeText(this, locality, Toast.LENGTH_SHORT).show();
double lat = add.getLatitude();
double lng = add.getLongitude();
gotoLocation(lat, lng, 4);
最佳答案
感谢您的帮助,我发现您的回答很有帮助。 我的问题解决了,我正在 MIUI 中文 ROM 上测试应用程序,安装 MIUI 国际 ROM 后,我的代码运行得非常顺利。
谢谢。
关于android - 当我搜索城市(或任何非国家/地区名称)时,Android 中的地理位置抛出异常与国家/地区名称配合良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33514398/