How to know the positioning mode is WIFI or 2G/3G cell tower in Android?

后端 未结 2 1546
终归单人心
终归单人心 2021-01-03 12:56

We know there are two positioning mode in Android: GPS and network. If we use network, then Android can use WIFI or 2G/3G cell tower to position. Without GPS, we can simply

相关标签:
2条回答
  • 2021-01-03 13:25

    Actually, there is a way to do this. It is not just documented well and thus might also change without notice. You can get the used location estimation method via the network location provider location update extra data.

    Bundle extras = location.getExtras();
    if (extras.containsKey("networkLocationType")) {
        String type = extras.getString("networkLocationType");
        if (type .equals("cell")) {
            // Cell (2G/3G/LTE) is used.
        } else if (type .equals("wifi")) {
            // Wi-Fi is used.
        }
    }
    
    0 讨论(0)
  • 2021-01-03 13:36

    This is correct, Android does not explicitely give a way to determine how the network location is computed. The principle of the network provider is to collect all the relevant data on the device, and then send it all to the Google servers, where your location is computed and sent back to you. I am not sure, but the network location might also use the accelerometer/gyro/compass data to improve the accuracy of the location, especially when you compute your location continuously. So I believe it can use simultaneously cell tower and Wifi info.

    Your accuracy method should work in most cases, but is not 100% reliable.

    Another possibility is to turn the wifi off, compute a first location fix, then turn it on again and give it another try. by comparing the two locations and their accuracy estimates, you can probably guess the influence of wifi on the location engine at your current location.

    Out of curiosity, why do you need this for?

    0 讨论(0)
提交回复
热议问题