在android中获取位置地址时出错

问题描述 投票:0回答:1

基于本教程:qazxsw poi。我现在可以根据位置获得纬度和经度。现在我',试图通过Geocoder获取确切的地址:(主要是上面的类代码属于)

http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/

LogCat说:

GPSTracker GPS = new GPSTracker(Main.this);

double latitude = GPS.getLatitude();
double longitude = GPS.getLongitude();

Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(Main.this, Locale.getDefault());
addresses = geocoder.getFromLocation(latitude, longitude, 1);
String address = addresses.get(0).getAddressLine(0);

我不知道我做错了什么?

android gps location
1个回答
0
投票
07-06 11:29:41.911: W/System.err(1670): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0

// if(addresses!= null && addresses.size()!= 0)...检查此部分..您的地址不能为空,并且数组的大小不应为零...

© www.soinside.com 2019 - 2024. All rights reserved.