这可能是SO的主题,如果是这样我道歉(并乐意接受关闭的标志),但我有问题找出WIFI打开时的原因,但没有连接到任何接入点(在我的
Android设备上),它大大提高了使用LocationManager时网络提供商的准确性.如果没有它,一般网络位置结果距离我当前位置大约1英里.此外,大多数时候返回的lat / lng值是不同的,所以它甚至没有请求一次并且只是在lastKnownLocation()中缓存结果
显然,我正在使用GPS和网络提供商来获得对最终用户位置的适当修复(当两者都不可用时),并使用时间戳来确定哪个是最新的.
我搜索过谷歌,并提出了各种答案,例如:“它只是做”和“它的魔力” – 说实话,这是毫无用处的.我不想深入描述内部工作,只是略低于“它只是做”,或“它是如何工作的”.
请求的代码
// first get location from network provider //
if(isNetworkEnabled)
{
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,MIN_TIME_FOR_UPDATES,MIN_DISTANCE_CHANGE_FOR_UPDATES,this);
Logging.Debug("GPSTracker","Network");
if(locationManager != null)
{
netLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if(netLocation != null)
{
latitude = netLocation.getLatitude();
longitude = netLocation.getLongitude();
speed = netLocation.getSpeed();
}
}
}
// if gps is enabled get lat/lng using that as well //
if(isGPSEnabled)
{
if(gpsLocation == null)
{
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,this);
Logging.Debug("GPSTracker","GPS Enabled");
if(locationManager != null)
{
gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(gpsLocation != null)
{
latitude = gpsLocation.getLatitude();
longitude = gpsLocation.getLongitude();
speed = gpsLocation.getSpeed();
}
}
}
}
非常感谢任何见解.谢谢.