Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

android - Get Latitude and Longitude without inserting Sim Card and Start/Stop Gps from Application

I am trying to fetch Gps latitude and longitude, but i am having a query that whenever i try to fetch Lat & Long without sim card, it is not providing any info where as soon i insert my sim card, it provides me all information in desired manner.

LocationManager mlocManager = 
    (LocationManager) getSystemService(Context.LOCATION_SERVICE);

LocationListener mlocListener = new MyLocationListener();

mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                                   0, 0, mlocListener);

you can see though i m using GPS_PROVIDER, it is not giving me Lat & Long without Network Operator help, can anybody tel me?


Another thing is How to start and stop GPS from an application means i wanna start gps after particular time and than as soon i get beslocation, i can turn it off.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't need to have access to any network to get a GPS location on Android. But an internet connection speeds-up the location fix from about 5 minutes to 5 seconds (approximately)! This improvement is brought by Assisted-GPS (A-GPS), as opposed to standalone-GPS.

GPS phones (including Android devices) check if a network connection is available. If so, they download assistance data from and A-GPS server and use it to compute the location fix with the GPS chipset. If not, the GPS chipset has to download the data from a GPS satellite, which takes a long time (rate is 50 bits per second!). The process can also be sped up if a GPS location has been computed not too long ago.

So first:

  • check that you have added ACCESS_FINE_LOCATION to your manifest's permissions
  • check that GPS satellites are enabled in the phone's settings
  • check that you are not indoors (signals from satellites 20,000 km above do not like roofs and walls)

Then start your app and wait, there can be a few minutes before the first fix is available.

As for starting the GPS from your app, it seems possible (see How can I enable or disable the GPS programmatically on Android?), but I don't know how! At least you can download Tasker and program it to start/stop the GPS.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...