Does LocationManager:NETWORK_PROVIDER work without GPS enabled?

a 夏天 提交于 2019-12-13 06:03:44

问题


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?

I promise, GPS is really disabled.

Can anyone tell me how this is possible?

I have this in my App:

in oncreate():

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

Method:

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

Listener:

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) {}
    };

回答1:


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.




回答2:


Yes, NETWORK_PROVIDER needs no GPS, but NETWORK_PROVIDER fetches location with low precision by wireless network site.




回答3:


Yes, NETWORK_PROVIDER doesn't requires GPS. Network provider access you location through Wireless network if GPS is not enabled but it is not accurate location. Enabling GPS will provide you with more accurate location results. The access coarse location and access fine location permissions in you meanifeast file differentiate it. With access coarse location you will get location without GPS but fine location can access GPS location too NETWORK_PROVIDER works with both permissions



来源:https://stackoverflow.com/questions/20539046/does-locationmanagernetwork-provider-work-without-gps-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!