Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve GPS location using android
    primarykey
    data
    text
    <p>I'm trying to get gps location of the current location using simple android program. I used <code>onLocationChanged()</code> method for this. But it returning the coordinates as 0.0. The users permission part is correct. This is the code of main one.</p> <pre><code>public class MainActivity extends Activity { GPSTracker gps; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button) findViewById(R.id.button1); final TextView tv = (TextView) findViewById(R.id.textView1); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub gps = new GPSTracker(MainActivity.this); double lat = gps.latitude; String mlat = String.valueOf(lat); tv.setText(mlat); } }); } } </code></pre> <p>this is the gps location class that im using...</p> <pre><code> public class GPSTracker extends Service implements LocationListener{ private final Context mContext; boolean isGPSEnabled = false; boolean canGetLocation = false; Location location; double latitude; double longtitude; protected LocationManager locationManager; public GPSTracker(Context context){ this.mContext = context; getLocation(); } public Location getLocation(){ locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); return null; } protected void onStart() { } protected void onPause(){ locationManager.removeUpdates(this); } @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub latitude = location.getLatitude(); longtitude = location.getLongitude(); } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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