在未启用GPS的情况下,LocationManager:NETWORK_PROVIDER是否可以工作? [英] Does LocationManager:NETWORK_PROVIDER work without GPS enabled?

查看:704
本文介绍了在未启用GPS的情况下,LocationManager:NETWORK_PROVIDER是否可以工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么即使GPS处于禁用状态,我的应用程序仍能找到位置.所以我问自己为什么这是可能的,而我对此知之甚少.也许NETWORK_PROVIDER不需要GPS?

I'm wondering why my app still finds location although the GPS is disabled. So I asked myselft why this is possible and I have too less knowledge about this. Maybe the NETWORK_PROVIDER needs no GPS?

我保证,GPS确实处于禁用状态.

I promise, GPS is really disabled.

谁能告诉我这怎么可能?

Can anyone tell me how this is possible?

我的应用程序中有这个

在oncreate()中:

locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);

方法:

public void getGpsLocation(){
    locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, myLocationListener, this.getMainLooper());
}

监听器:

LocationListener myLocationListener = new LocationListener() {

        // When location has changed
        public void onLocationChanged(Location location) {

            locationManager.removeUpdates(this);

            locationAll = location;

            // positionOnceFound = true  --> location was already found and no further update necessary
            //if (location != null && positionOnceFound == false) 
            if (location != null) 
            {
                // location is found, no more update necessary --> true
                positionOnceFound = true;

                // get Lat/Lon of my current position
                myPosLat = location.getLatitude();
                myPosLon = location.getLongitude();

                // For calculating the point B(right top corner) and point C(left bottom corner
                // Lat/Lon of B and C needed for getting the prices from this area around my position
                double dy = 5.0 / 110.54; // 5.0 -> 5km to vertical
                double dx = 5.0 / (111.320 * Math.cos(myPosLat / 180 * Math.PI)); // 5km to horizontal

                // Get point B
                rightTopCornerLon = myPosLon + dx;
                rightTopCornerLat = myPosLat + dy;
                // Get point C
                leftBottomCornerLon = myPosLon - dx;
                leftBottomCornerLat = myPosLat - dy;

                System.out.println("Alat: " + myPosLat + " Alon: " + myPosLon + " Blat: " + rightTopCornerLat + " Blon: " + rightTopCornerLon +
                      " Clat: " + leftBottomCornerLat + " Clon: " + leftBottomCornerLon);

                getCityName(isItStartOrStop);


             }
        }
        public void onProviderDisabled(String provider) {}
        public void onProviderEnabled(String provider) {}
        public void onStatusChanged(String provider, int status, Bundle extras) {}
    };

推荐答案

网络提供商需要ACCESS_COARSE_LOCATION的许可,因此它可以工作,并且可以使用WIFI网络或移动网络为您提供位置更新,这可能不是如此精确,但比使用GPS获取位置更新更快.

The network provider requires the permission of ACCESS_COARSE_LOCATION, so it will work and provide you location updates using the WIFI networks, or Mobile networks, this may not be so accurate but is faster than getting a location update using the GPS.

这篇关于在未启用GPS的情况下,LocationManager:NETWORK_PROVIDER是否可以工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆