【发布时间】:2014-03-27 10:44:30
【问题描述】:
我是 android 新手,正在使用 Google maps V2 开发应用程序。我设计了地图,一切都很好。我在顶部放置了一个文本框和按钮,帮助用户搜索他想要的任何位置,并使用这个底部方法进行搜索操作。用户输入无效位置时应用程序崩溃的问题。 我想在这个方法中用 toast 添加条件,当用户输入无效位置时,toast 出现(请输入有效位置)
请帮帮我
public void search(View v) throws IOException{
EditText textbox = (EditText) findViewById(R.id.editText1);
String location = textboxt.getText().toString();
if (location.length() == 0) {
Toast.makeText(this, "Please Enter a location", Toast.LENGTH_SHORT).show();
return;
}
Geocoder gc = new Geocoder(this);
List<Address> list = gc.getFromLocationName(location, 1);
Address add = list.get(0);
String locality = add.getLocality();
double lat = add.getLatitude();
double lng = add.getLongitude();
LatLng ll = new LatLng(lat, lng);
Gmap.moveCamera(CameraUpdateFactory.newLatLng(ll));
// zoom in Google map
Gmap.animateCamera(CameraUpdateFactory.zoomTo(20));
【问题讨论】:
-
是的,代码运行良好(y)
标签: java android google-maps search