fan*_*tly 7 gps android android-wifi
这可能是题外话了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,
MIN_TIME_FOR_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES,
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();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
非常感谢任何见解.谢谢.