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。哪位大侠能解释一下,权限也设置了,不知道问题出在哪,求解答。
解决方案 »
- 如何减小使用AudioRecord采集音频时的延迟?
- 我想限制返回键返回某个界面,请问这个可以时间吗
- android engine
- 求助高手!我的线程运行时间不同!
- android模拟器运行一个程序时打印出以下信息,大家给看下
- 把Android的"Dev Guide"下载下来了,不过看多了眼睛痛,大家有没有好办法?
- inflate() android sdk中调用该方法调试时报Source not found问题
- 搜狗浏览器收藏夹为什么不能在线更新
- Handler.post 监听模式处理UDP数据的疑问
- 如何准确调出Android系统相册
- 求linux下异常打印定位故障的文章
- 蓝牙支持多线程传输吗?
send过了,经纬度没有问题,我直接搜的城市经纬度,是在范围内的,而且是没有报相关的异常。另外,
我直接把经纬度写到参数中,
addresses=gc.getFromLocation(latitude, longitude,1);
为什么返回的也是空列表啊?
不知道什么原因?
"getLastKnownLocation常常取不到location“是什么原因啊,需要设置什么东西吗?"requestLocationUpdates",我是不想频繁的更新的,最好是程序启动时更新一次位置就行。自己模拟gps信号是什么意思,能不能说的详细一点。
我就是在建模拟器的时候,把支持gps属性加上了
其它就是在DDMS中Emulator Control中,send一下经纬度。