使用LocationManager时,为什么启用Wifi但未连接有助于网络位置?

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)

非常感谢任何见解.谢谢.

Ale*_*ien 2

Android、Apple 和其他公司可以访问庞大的数据库,在其中可以查找 Wlan-Device-Id(WLAN 路由器的 Mac 地址)到纬度/经度坐标。
因此,当您的手机检测到“已知”WLAN 时,它可以:
- 查找要协调的 WLAN-id 的本地缓存,或者如果您有活动的互联网连接,
- 它可以通过该连接并查询 WLAN id 的坐标数据库。

剩下的问题是他们在哪里有你的 WLAN-id 坐标?
可能是您第一次在连接到 WLAN 时激活 GPS。

SkyHook就是这样一家提供此类数据的公司。