Cannot get current location until connected to the

2019-07-29 11:11发布

问题:

my question title is kind of self explanatory. When I want to get my current location, for the first time(after phone start up), I have to be connected to the internet. After getting the location once, my app no longer needs the internet connection and the update happens just fine. At first I thought there was something missing in my code, but I tried the in-build maps application, and it also couldn't get my location until I enabled data transfer.

This seems really strange to me, if I can get coordinates without net connectivity after the first coordinate is aquired, why do I need it in the first place?

So I was wondering 2 things, 1 - is there a work around to let me get my first Location without being connected and 2 - if there is no work around is it practical to ask the user to enable it? I'm not 100% on this but I'm pretty sure I cant enable data programatically.

Would like to hear your opinions. Thanks :)

回答1:

Android devices use what's called aGPS - the a stands for assisted. The most basic I've seen it explained is that certain information has to be downloaded and a general, broad location identified in order to allow the GPS sensor to know where to look for the satellites. Once it has the information, it can find the GPS satellites, and is fine. There is no way for your app to get around that fact, I'm afraid.



回答2:

Have you defined <uses-permission android:name="android.permission.INTERNET" /> in AndroidManifest.xml

If yes then check you internet connection:

Or

Check My Answer Here: Get current latitude and longtitude