Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3935014
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:46:54+00:00 2026-05-19T23:46:54+00:00

I have a question about services in Android. I want to know what’s the

  • 0

I have a question about services in Android. I want to know what’s the best approach to get the Location variables from GPS. I am doing an application with geolocation using a service wich implements the GPS module. And for getting the location I create a variable in the class static and public method static to be called from outside the class, and that is it. To retrieve the position from the GPS I just used in my classes:

Location mLocation = ServiceGPS.getLocation();
The class ServiceGPS has this method:

public static Location getLocation(){
return mLocation;
}

I dont really see the point of binding to a service in this case, as I just have to call the static method. I also was thinking of doing a base class or implements the LocationListener, but this way is really simple and it works and saves code writting.

Thanks a lot for your help, and sharing your knowledge with me.

BR. David.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:46:55+00:00Added an answer on May 19, 2026 at 11:46 pm

    You can’t just “get” the location in Android, as it may come from different places (the last-known location, the GPS receiver, the wifi network location, or the mobile data network) and more importantly it may take time to receive the location or you may not get one at all (e.g. GPS present, but no signal as indoors).

    The fact that it may take time to get the location means you MUST run the location-seek on a separate thread, unless there is a previously cached location. Otherwise your application will lock up until the location is acquired (which may never happen, e.g. on a device with no GPS or geo-locating network).

    This is the key page you need to read, digest, and use:
    http://developer.android.com/guide/topics/location/obtaining-user-location.html
    If you’re new to geo-location in Android, use the example code to start with.

    The things I’ve learnt adding geo-location to apps are…

    • Never assume there are location providers. The device may have no network connection, or no GPS. You need error handling in the code to handle those scenarios.
    • Always use threads to do geo-lookup to keep the app responsive
    • Try to use the Android last-known location if possible, it provides a quick lock. You could update the location in the background to a more accurate one.
    • If the app may run on devices that cannot do geo-location (e.g. cheaper tablets, Google TV etc) store the location in preferences, so the user specific it once, and it uses that each time the app loads (if it cannot find a new location)
    • It often makes sense to create a class specifically to manage getting locations, threading, etc. Then other classes within your app can simply call a static method just like you suggest, but the challenge is the code you use to get a value into your variable mLocation!
    • You may not get a location at all – don’t assume you will, devices & contexts vary.
    • Unless you MUST have a very accurate location, always use the network location providers too as they are often very quick. A GPS location lookup from fresh can be very slow, and users will get bored and frustrated. Google Maps seems quite quick, but it actually does quite a bit of location caching, and you’ll see sometimes it is slow to get a fresh location.

    I recommend Mark Murphy’s e-books on Android, he has excellent coverage and source code examples for geolocation http://commonsware.com/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a comprehension question about Android Services. I have a Service that performs
i have a question about Services in Android. I have a application with two
I'm about to start using location services, but have a general question about how
This question about Timers for windows services got me thinking: Say I have (and
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The
I'm creating Analysis Services cubes in Visual Studio BIDS, and have a question about
I would ask a semi-theorical question about web services and client-server architecture. I have
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about XSLT1.0. The task is to write out in HTML all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.