我有一个需要用户当前位置的应用程序。在应用程序中,我注册了两个位置提供商来监听位置,此外我还检查了最后一个已知位置。但应用程序并不总是收到位置。我今天发现的令人惊讶的事情是,
GPS 已关闭
但无线网络的位置已打开。
我打开谷歌地图,我可以看到它非常准确地显示了当前位置。但是当我打开我的应用程序时,它无法获取位置。
看到这一点我很惊讶,我认为谷歌地图正在做一些事情来接收位置,而不是我所做的。
这是我注册位置的方式
locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
Location location = null;
try {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 10, 100, this);
Location location1 = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location1 != null)
location = location1;
Log.v(TAG, "Network listener Enabled");
} catch (RuntimeException ee) {
// TODO: handle exception
Log.e(TAG, "Network Providers Disabled");
}
try {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 10, 100, this);
Location location1 = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Log.v(TAG, "GPS listener enabled");
if (location1 != null)
location = location1;
} catch (RuntimeException e) {
Log.e(TAG, "GPS not available");
}
我不知道我是否还有其他需要做的事情。请帮我。