We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package com.example.gpstracking;
import android.app.Activity; import android.location.Criteria; import android.content.Context; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.location.LocationListener; import android.util.Log; import android.view.Menu; import android.widget.TextView; import android.widget.Toast;
public class MainActivity extends Activity implements LocationListener { LocationManager locationManager; String provider;
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Getting locationManager object locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); //creating an empty criteria object Criteria Criteria = new Criteria(); //Getting the name of provider that meet the criteria provider = locationManager.getBestProvider(Criteria, false); if(provider!=null && !provider.equals("")){ Location location = locationManager.getLastKnownLocation(provider); locationManager.requestLocationUpdates(provider ,800000,1, this ); if(location!= null) onLocationChanged(location); else Toast.makeText(getBaseContext(), "Location can't be found" ,Toast.LENGTH_LONG) .show(); } else { Toast.makeText(getBaseContext(), " No provider found" , Toast.LENGTH_SHORT).show(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; }
@OverRide public void onLocationChanged(Location location) {
//Getting reference to tv_Longitude TextView tvLongitude = (TextView)findViewById(R.id.tv_longitude); tvLongitude.setText("Longitude:" + location.getLongitude()); // Getting reference to tv_Latitude TextView tvLatitude = (TextView)findViewById(R.id.tv_latitude); tvLatitude.setText("Latitude:" + location.getLatitude()); }
@OverRide public void onProviderDisabled(String provider){
Log.d("Latitude","disable");
}
@OverRide public void onProviderEnabled(String provider){ Log.d("Latitude","enable");
@OverRide public void onStatusChanged(String provider , int status, Bundle extras) { Log.d("Latitude","status");
The text was updated successfully, but these errors were encountered:
No branches or pull requests
package com.example.gpstracking;
import android.app.Activity;
import android.location.Criteria;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.location.LocationListener;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements LocationListener {
LocationManager locationManager;
String provider;
@OverRide
public void onLocationChanged(Location location) {
@OverRide
public void onProviderDisabled(String provider){
}
@OverRide
public void onProviderEnabled(String provider){
Log.d("Latitude","enable");
}
@OverRide
public void onStatusChanged(String provider , int status, Bundle extras) {
Log.d("Latitude","status");
}
The text was updated successfully, but these errors were encountered: