【发布时间】:2011-01-24 09:25:24
【问题描述】:
我的代码如下:
Geocoder geocoder = new Geocoder(this,Locale.UK );
List<Address> addresses = null;
Toast.makeText(displaybyName.this, "country: before " , Toast.LENGTH_SHORT).show();
try {
Toast.makeText(displaybyName.this, "country: before " , Toast.LENGTH_SHORT).show();
addresses = geocoder.getFromLocationName(
"Camden", 1);
if (addresses.size() > 0) {
geopoint = new GeoPoint(
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
//Animating on display
mapcontroller.animateTo(geopoint);
mapcontroller.setZoom(5);
mapview.invalidate();
}
} catch (IOException io) {
// TODO Auto-generated catch block
Toast.makeText(displaybyName.this, "Connection Error", Toast.LENGTH_SHORT).show();
}
if (addresses.size() > 0) {
geopoint = new GeoPoint(
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
//Animating on display
mapcontroller.animateTo(geopoint);
mapcontroller.setZoom(5);
mapview.invalidate();
}
但是,应用程序每次都会崩溃。地理编码器未返回任何纬度/经度。
代码有什么问题吗...请指教。
【问题讨论】:
-
“崩溃” - 我们需要有关失败的更多详细信息(描述、堆栈跟踪......)
-
你真的需要在你的 LogCat 窗口中找到错误(在 DDMS 透视图上,如果你不能看到它)
-
另外,你似乎重复了你的 IF 逻辑,一次在 try-catch 内,一次在之后。
标签: java google-geocoder