Cannot get current location until connected to the internet - Android GPS

与世无争的帅哥 提交于 2019-12-11 06:35:58

问题


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



来源:https://stackoverflow.com/questions/19270154/cannot-get-current-location-until-connected-to-the-internet-android-gps

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