Get cell phone position. GPS

Asked

Viewed 1,080 times

1

I have an application, where I need to get the coordinates of where the phone is time I open the registration form and then when I register, to store the 2 locations. How do I get the location of the phone?

1 answer

2


1. Define in the manifest that will use the GPS:

   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">

2. Create a Locationmanager

LocationManager gerenciadordeLugar = (LocationManager)   : getSystemService(Context.LOCATION_SERVICE);

3. Check that the GPS is on.

4. Implement a Listener and get the coordinates:

LocationListener meuListener = new MeuListener();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 5000, 10, meuListener);

Complete example in gist

  • In step 3, check if the GPS is on, I have to do this manually?

  • Yeah, and if you look at the code I posted on gist you will see that this code in that part: flag = displayGpsStatus();

  • And this Locationlistener is imported from android.Location or com.google.android.gms.Location?

  • And what will become of the Istener?

  • @meisterx7 import android.location.LocationListener;. Please see gist. It’s all there.

  • Friend, please.. I am studying Android Studio and GPS, but this gist code this OFF !?! Please have another place for me to consult and see how it works.. I really wanted to learn this! THANK YOU!

  • 1

    @Camilayamamoto changed my name on github a little while ago, I forgot that this was there. Thanks for telling ( tidy link)

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.