Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the users location

Tags:

android

I am developing an android application. I need to find the location of the user as soon as he/she logs in to the application. I do not want maps to be displayed, the location should be identified without the user's knowledge. Is it possible to do this using the Google maps API? or is there any other way to do this?

Thanks

like image 924
Sindu_ Avatar asked Feb 20 '23 18:02

Sindu_


1 Answers

The best way to do this is to use the PASSIVE location provider like so:

LocationManager lm = (LocationManager)yourActivityContext.getSystemService(Context.LOCATION_SERVICE);
Location lastKnown = lm.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);

This returns the last known location received by the operating system, so this may be stale, but you can check when the location was retrieved, and by which provider by querying the location object.

In conclusion, the user will have no idea that you've gotten a location except that your app will require the proper location permission(s).

like image 132
hwrdprkns Avatar answered Mar 08 '23 07:03

hwrdprkns