by vipulshah2010 » Fri Mar 05, 2010 9:23 am
package org.GPS;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
public class GPS extends Activity implements LocationListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = new Intent();
ComponentName comp = new ComponentName("com.android.settings",
"com.android.settings.SecuritySettings");
i.setComponent(comp);
startActivity(i);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,1, 1,this);
Location currentLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(currentLocation != null)
{
double Latitude = currentLocation.getLatitude();
double Longitude = currentLocation.getLongitude();
Toast.makeText(GPS.this,"Latitude="+Latitude+"\nLongitude"+Longitude,Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(GPS.this,"No GPS 1",Toast.LENGTH_LONG).show();
}
}
@Override
public void onLocationChanged(Location location)
{
if (location != null)
{
double longitude = location.getLongitude();
double latitude = location.getLatitude();
Toast.makeText(GPS.this,"Longiude="+longitude+"\nLatitude="+latitude,Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(GPS.this,"No GPS 2",Toast.LENGTH_LONG).show();
}
}
@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
}
}