In this tutorial i will show you how to quickly get the gps data using your android device version 1.6+.
All you have to do is to implement one interface and acquire LocationMangager from the adnroid system service.
public class LocationExampleAct extends Activity implements LocationListener{
private double latitude;
private double longitude;
private LocationManager locMgr = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationTxt = (TextView)findViewById(R.id.location_id);
locMgr = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
this.latitude = location.getLatitude();
this.longitude = location.getLongitude();
this.locationTxt.setText("Location: "+this.latitude +" : " + this.longitude);
Log.i("Location change",""+latitude+ " : "+longitude) ;
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
private double latitude;
private double longitude;
private LocationManager locMgr = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationTxt = (TextView)findViewById(R.id.location_id);
locMgr = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
this.latitude = location.getLatitude();
this.longitude = location.getLongitude();
this.locationTxt.setText("Location: "+this.latitude +" : " + this.longitude);
Log.i("Location change",""+latitude+ " : "+longitude) ;
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}