Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>public class GPSLocationBased extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.locationbased); LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener ll = new Mylocationlistener(); // ---Get the status of GPS--- boolean isGPS = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); // If GPS is not enable then it will be on if(!isGPS) { Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE"); intent.putExtra("enabled", true); sendBroadcast(intent); } //&lt;--registers the current activity to be notified periodically by the named provider. Periodically, //the supplied LocationListener will be called with the current Location or with status updates.--&gt; lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll); } /** *Mylocationlistener class will give the current GPS location *with the help of Location Listener interface */ private class Mylocationlistener implements LocationListener { @Override public void onLocationChanged(Location location) { if (location != null) { // ---Get current location latitude, longitude, altitude &amp; speed --- Log.d("LOCATION CHANGED", location.getLatitude() + ""); Log.d("LOCATION CHANGED", location.getLongitude() + ""); float speed = location.getSpeed(); double altitude = location.getAltitude(); Toast.makeText(GPSLocationBased.this,"Latitude = "+ location.getLatitude() + "" +"Longitude = "+ location.getLongitude()+"Altitude = "+altitude+"Speed = "+speed, Toast.LENGTH_LONG).show(); } } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } } </code></pre> <p>}</p> <p>Through this code u will get ur lat and long. and u may use it on ur gmap. this code also start gps functionality problematically. Hope this will help u.. All the best :) </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload