【发布时间】:2016-03-18 21:22:24
【问题描述】:
我遇到了一个问题。如果我关闭 GPS,然后再次打开 - getLastKnownLocation() 返回 null。 在这种情况下,获取当前坐标的唯一方法是 LocationListener。 (如果我错了,请纠正我)。
所以我打电话给听众:
locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 10, (float) 0.01, locationListener );
.....
public void onLocationChanged(final Location loc)
{
try {
addresses = geoCoder.getFromLocation( loc.getLatitude(), loc.getLongitude(), 1);
if (addresses.size() > 0)
{
String cityName = addresses.get(0).getLocality();
String streetName = addresses.get(0).getAddressLine(0);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
找到该位置大约需要一分钟(!)。尽管一旦找到它,它就会每秒更新一次。但它仍然对我没有多大帮助。
我需要尽快找到当前坐标。那怎么办?为什么第一次调用 onLocationChanged 的速度如此之慢,但接下来的时间却快得多?
【问题讨论】:
-
我觉得你应该先用wifi来获取位置然后换成gps。gps很慢。
标签: android geolocation location