GPS定位的问题,location对象为空
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location == null)
{
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
Log.i(TAG, "location= " + location +" locationManager= " + locationManager);
String addressString = null;
double latitude=location.getLatitude();
double longitude=location.getLongitude();
Geocoder gc=new Geocoder(this,Locale.getDefault());
try
{
List<Address> addresses=gc.getFromLocation(latitude, longitude,1);
StringBuilder sb=new StringBuilder();
Log.i(TAG, "addresses= " + addresses);
if(addresses.size()>0)
{
Address address=addresses.get(0);
for(int i=0;i<address.getMaxAddressLineIndex();i++)
sb.append(address.getAddressLine(i)).append("\n");
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
addressString=sb.toString();
Log.i(TAG, "latitude= " + latitude +" longitude= " + longitude + " city= " + addressString);
}
}
catch(IOException e)
1. 为什么获得的location对象都是null啊?
2. 把经纬度写死后,用Geocoder解析时,返回的是一个 空list。
哪位大侠能解释一下,权限也设置了,不知道问题出在哪,求解答。
...全文


