Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 2.20 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. emulator restarts every time in finding location using gps
  2. package com.android.gpsloc;
  3.  
  4. import android.app.Activity;
  5. import android.content.Context;
  6. import android.location.Location;
  7. import android.location.LocationListener;
  8. import android.location.LocationManager;
  9. import android.os.Bundle;
  10. import android.widget.Toast;
  11.  
  12. public class Gpsloc extends Activity    
  13. {          
  14.      @Override    
  15.        public void onCreate(Bundle savedInstanceState)    
  16.          {      
  17.           super.onCreate(savedInstanceState);    
  18.           setContentView(R.layout.main);    
  19.           LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);    
  20.           LocationListener mlocListener = new MyLocationListener();    
  21.           mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);    
  22.            }    
  23.          public class MyLocationListener implements LocationListener    
  24.         {    
  25.           @Override    
  26.              public void onLocationChanged(Location loc)    
  27.              {    
  28.               loc.getLatitude();    
  29.               loc.getLongitude();    
  30.               String Text = "My current location is: " +    
  31.               "Latitud = " + loc.getLatitude() +    
  32.               "Longitude = " + loc.getLongitude();    
  33.               Toast.makeText( getApplicationContext(),    
  34.               Text,    
  35.               Toast.LENGTH_SHORT).show();    
  36.             }
  37.  
  38.               @Override    
  39.                    public void onProviderDisabled(String provider)    
  40.                        {    
  41.                         Toast.makeText( getApplicationContext(),
  42.                         "Gps Disabled",    
  43.                         Toast.LENGTH_SHORT ).show();    
  44.                         }
  45.               @Override    
  46.                    public void onProviderEnabled(String provider)    
  47.                       {    
  48.                        Toast.makeText( getApplicationContext(),    
  49.                        "Gps Enabled",    
  50.                        Toast.LENGTH_SHORT).show();    
  51.                        }    
  52.               @Override    
  53.                    public void onStatusChanged(String provider, int status, Bundle extras)    
  54.  
  55.                 }    
  56.            }    
  57.       }