Questions tagged [android-location]

android-location refers to the location API provided by the Android framework.

References

1355 questions
212
votes
10 answers

Good way of getting the user's location in Android

The problem: Getting the user's current location within a threshold ASAP and at the same time conserve battery. Why the problem is a problem: First off, android has two providers; network and GPS. Sometimes network is better and sometimes the GPS is…
Nicklas A.
  • 6,501
  • 7
  • 40
  • 65
132
votes
3 answers

How to get current location in Android

I'm having troubles of getting my current position coordinates using the NETWORK provider of android location system. Already read a lot of tutorials and implemented 4 or 5 existing classes to my project and all of them are giving me the last…
Boris Pawlowski
  • 1,781
  • 4
  • 16
  • 22
97
votes
5 answers

When should I use ACCESS_COARSE_LOCATION permission?

I am building an Android app that will track the user's geolocation and draw their route on a map. I am using the Google Play Services location API, as described here. It is intuitive that my application requires the ACCESS_FINE_LOCATION permission,…
78
votes
3 answers

Background service with location listener in android

I am creating a background service that will run in its own process. It should allow me to listen if the device location has changed. I should be able to change criteria like the distance moved before notifying the UI. How can I do the same? I…
Nilanchala
  • 5,891
  • 8
  • 42
  • 72
77
votes
8 answers

How to get the current location latitude and longitude in android

In my application, I get the current location's latitude and longitude when application is open, but not when the application is closed. I am using Service class to get the current location latitude and longitude in my application. Please tell me…
Anil M H
  • 3,332
  • 5
  • 34
  • 51
51
votes
3 answers

Minimal android foreground service killed on high-end phone

I'm trying to create an app that lets users log routes (locations/GPS). To ensure locations are logged even when the screen is off, I have created a foreground service for the location logging. I store the locations in a Room Database which is…
44
votes
14 answers

Why is FusedLocationApi.getLastLocation null

I am trying to get location by using FusedLocationApi.getLastLocation and I've got the location permissions in the manifest file:
38
votes
12 answers

Error adding geofences in Android (status code 1000)

I am getting an error in the onAddGeofencesResult(int statusCode, String[] geofenceRequestIds) callback with statusCode = 1000. I have my GPS enabled and my WiFi. I also have Google Play Services and I am able to track my location and request…
35
votes
3 answers

Change Location Mode to High Accuracy Programmatically Android

Is it possible to get the information on the location mode which the user has selected among the three modes under the location settings options i.e 1.Hight Accuracy 2.Battery Saving 3.GPS Only I want to programmatically check if user has selected…
ik024
  • 3,566
  • 7
  • 38
  • 61
33
votes
7 answers

Android Location Manager, Get GPS location ,if no GPS then get to Network Provider location

I am using this given below code to get locations: public Location getLocation() { try { mLocationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE); // getting GPS status boolean…
TechFanatic
  • 1,218
  • 4
  • 13
  • 31
33
votes
9 answers

Get the distance between two locations in android?

i need to get distance between two location, but i need to get distance like blue line in the picture. I try next: public double getDistance(LatLng LatLng1, LatLng LatLng2) { double distance = 0; Location locationA = new Location("A"); …
Kostya Khuta
  • 1,846
  • 6
  • 26
  • 48
31
votes
4 answers

Determining the speed of a vehicle using GPS in android

I would like to know how to get the speed of a vehicle using your phone while seated in the vehicle using gps. I have read that the accelerometer is not very accurate. Another thing is; will GPS be accessible while seated in a vehicle. Won't it have…
John Kulova
  • 477
  • 1
  • 10
  • 20
30
votes
4 answers

Fused Location Provider unexpected behavior

this is how I register my app to receive location updates: mLocationRequest = LocationRequest.create(); mLocationRequest.setInterval(Consts.ONE_MINUTE *…
28
votes
9 answers

Geocoder.getFromLocation grpc failed on Android real device

I need to get the city and state from latitude and longitude. Geocoder does this function to get the city and state. But I am getting an error java.io.IOException: grpc failed in below line only on Android real device. It is working fine in…
27
votes
5 answers

Stop Location Listener in Android

In my android app I need to get current GPS location of the user at the start of the application only if location has change from the previous location. But the problem is when I inside the application if location change (ie If user was traveling…
Chrishan
  • 4,076
  • 7
  • 48
  • 67
1
2 3
90 91