Getting Android User Location

I am looking for the best way to get the user's location. I found two main ways:

  • Using com.google.android.gms.location.LocationListener on Google Play Services.
  • Using android.location.LocationListener from Android API

My question is simple: which one is better?

At the moment I am using the first, but I have problems: when using a cellular network, my location is never retrieved.

Thank you for your help.

+6
source share
3 answers

My suggestion is the first. com.google.android.gms.location.LocationListener abstracts the place for layout of your code. For an example of a code look here . It works great for me with a cellular network or Wi-Fi.

+1
source

Although this post is really old, but I thought I should answer it so that it also refines my concept. See the link below:

 https://developers.google.com/maps/documentation/android/location 

It says:

Note that the My Location layer does not return any data. If you want to programmatically access location data, use the Location API.

So, I think using com.google.android.gms.location.LocationListener from Google Play Services may be easier, but if you want to access location data (exactly in my case) and want to do something about it the better to use android.location.LocationListener from the Android API.

+2
source

I am one of the developers of the new Gps app and touchscreen toolkit for Android. We studied this api during development, but found that using android.location.LocationListener is suitable for most purposes. The other interface is much more complicated and takes a little longer to implement. I suggest android.location.LocationListener .

The Location class, which is provided to you by the interface, provides many methods that you can use to get latitude, longitude, speed, distance to another point, carrier, etc.

Also view GpsStatus.Listener and GpsStatus.NmeaListener for satellite data.

0
source

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


All Articles