问题
Do Android devices need internet when using network provider for location fetching? I see few articles saying it works without internet and few saying it needs internet.
I am looking more into how Android internally does location fetching (rather than the code).
Articles saying we need internet: Device captures cell id and wifi hotspots and sends it to google server. And google server returns the location information. These articles are saying we need internet to get location.
Few articles are saying location is determined using cellular triangulation and no internet is needed.
I have tried to do test to confirm the same. But test results are confusing and could not deduce anything from the same.
Device configuration: I have turned off internet, wifi scan and GPS. This means device had only cellular signal. Application captures location every minute.
Test result 1:
- I was not able to get location using the above device configuration. I ran this test for 15+ mins.
- Then I turned on 3G data and I was getting the location.
- Post this, again I turned off the 3G, I was still able to get location with varying accuracy.
Testcase 2: (Continued post testcase1)
- Post testcase 1, I was getting the location consistently at office location.
- Then I travelled home and when I checked location in basement (-1 floor), I have got location with accuracy of ~900m for the first reading and no location for second and further readings. This continued for 20 odd mins.
- After 20 mins, I started receiving locations.
How exactly do network location works. I am looking more at how Android internally does location fetching rather than the code.
So here are my questions:
- Does it pass cellid and wifi hotspots and get location (using internet)?
- Does it do cellular triangulation?
- Does it cache data and use accelerometer and compass to determine location without internet?
(Though there are similar questions in stackoverflow. They are more into code rather than the Android internal working. Hence posting this question)
回答1:
When developing a location-aware application for Android, you can utilize GPS and Android's Network Location Provider to acquire the user location. Although GPS is most accurate, it only works outdoors, it quickly consumes battery power, and doesn't return the location as quickly as users want.
Android's Network Location Provider determines user location using cell tower and Wi-Fi signals
, providing location information in a way that works indoors and outdoors, responds faster, and uses less battery power. To obtain the user location in your application, you can use both GPS and the Network Location Provider, or just one.
If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the permission ACCESS_FINE_LOCATION
ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER
depending on the permission which you are using may give the different results
check these website and strategies used by android for location
depending on the comments of Anil vk
network –> (AGPS, CellID, WiFi MACID)
: This provider determines location based on availability of cell tower and WiFi access points. Results are retrieved by means of a network lookup. Requires either of the permissions android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
the answer is yes
it depends on the signal strength from cell tower to get accurate results you can see this website for accuracy and battery draining issues by using different ways.
来源:https://stackoverflow.com/questions/36760123/do-network-location-provider-need-internet-to-determine-location