GPS service in Android

I have a question about Android services. I want to know what is the best approach to get location variables from GPS. I am making a geolocation application using a service that implements a GPS module. And to get the location, I create a variable in the static and public method of the class, which is called from outside the class, and that’s all. To get position from GPS, I just used in my classes:

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

public static Location getLocation () {return mLocation; }

In this case, I really do not see the point of binding to the service, since I just need to call the static method. I also thought about making a base class or implementing a LocationListener, but this method is really simple and it works and saves the code.

Thank you very much for your help and share your knowledge with me.

BR. David.

+3
source share
2 answers

You can't just “get” the location on Android, as it can come from different places (the last known location, GPS, Wi-Fi network location or mobile data network), and more importantly, it takes time to get the location , or you cannot receive it at all (for example, GPS is present, but there is no signal in the room).

, , , , . , ( , , GPS ).

, , : http://developer.android.com/guide/topics/location/obtaining-user-location.html Android, .

, , ...

  • , . GPS. .
  • -, .
  • Android, , . .
  • , (, , Google TV ..), , , , ( )
  • , , .. , , - , mLocation!
  • - , , .
  • , , . GPS , . Google , , , , .

Android, http://commonsware.com/

+9

... , , . , . , , . . :

, . , LocationListener, , .

, , , . , : Location Android?

0

Source: https://habr.com/ru/post/1790690/


All Articles