I want to ask if there is another way to take user position with out using the map.I want only the position to make some queries with it .Is there any smarter and more efficient way to do this with out including map activity in android ?
Asked
Active
Viewed 525 times
-1
-
3Here you go: https://developer.android.com/training/location/index.html – samugi Nov 14 '16 at 21:26
1 Answers
1
Android has two basic ways to determine a user’s location. The first is to use the built-in location APIs that have been available since Android was first introduced. and there is Google Play Services .
So as you said without using map :
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
longitude = location.getLongitude();
latitude = location.getLatitude();
}
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
};
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener);
Don't forget permission if you want to use GPS:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Check this documentation for more : https://developer.android.com/guide/topics/location/strategies.html

Selim Ajimi
- 344
- 6
- 21