gpt4 book ai didi

android - 为什么在使用 LocationManager 时打开 Wifi 但未连接有助于网络定位?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:05:37 29 4
gpt4 key购买 nike

这可能是 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();
}
}
}
}

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

最佳答案

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

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

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

关于android - 为什么在使用 LocationManager 时打开 Wifi 但未连接有助于网络定位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21734907/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com