Google - Find location using gps in android, How to find location using gps in android
Find location using gps in android
Below code in android will help you to find location using gps in android. There are build in functions to find location and this function can be applied as below to find the location of gps from an android device.public class MainActivity extends Activity implements LocationListener { LocationManager myLocationManager ; String myProvider; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Getting LocationManager object myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); // Creating an empty criteria object Criteria myCriteria = new Criteria(); // Getting the name of the provider that meets the criteria myProvider = myLocationManager.getBestProvider(myCriteria, false); if(myProvider!=null && !myProvider.equals("")){ // Get the location from the given provider Location location = myLocationManager.getLastKnownLocation(myProvider); myLocationManager.requestLocationUpdates(myProvider, 20000, 1, this); if(location!=null) { // Getting reference to TextView displayview to display data TextView displayview = (TextView)findViewById(R.id.displayview); // Setting Current Longitude & Latitude displayview.setText("Longitude:" + location.getLongitude() + " Latitude:" + location.getLatitude()); } else Toast.makeText(getBaseContext(), "Location can't be retrieved", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(getBaseContext(), "No Provider Found", Toast.LENGTH_SHORT).show(); } }
The topic on Google - Find location using gps in android is posted by - Guru
Hope you have enjoyed, Google - Find location using gps in androidThanks for your time