gps location value dont print android
in this code i want to get the longitude and latitude and convert them to
string to use it on the screen and sms so how can i deal with it should i
do new class ? or this code is just modified
what should i do to make it work i used all permitions for locations
public class MainActivity extends Activity implements LocationListener {
Location location; // location
LocationManager locationManager;
public String LatTxt;
public String LonTxt;
public Double latitude; // latitude
public Double longitude; // longitude
TextView latTextView = (TextView) findViewById(R.id.Latitude_Txt);
TextView lonTextView = (TextView) findViewById(R.id.Longitude_Txt);
// The minimum distance to change Updates in meters
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10
meters
// The minimum time between updates in milliseconds
private static final long MIN_TIME_BW_UPDATES = (long) (1000 * 60 *
0.25); // 0.25
//
minute
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocationManager locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
LocationListener locListener = new MyLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES,locListener);
lonTextView.setText(" " + location.getLongitude());
latTextView.setText(" " + location.getLatitude());
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
latitude = location.getLatitude();
LatTxt = latitude.toString();
longitude = location.getLongitude();
LonTxt = longitude.toString();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
No comments:
Post a Comment