Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DataGPS extends Activity {
- private LocationManager locationManager;
- @Override
- protected void onCreate(Bundle savedInstanceState) {// В onCreate ОПРЕДЕЛЯЕМ TextView КОМПОНЕНТЫ И ПОЛУЧАЕМ locationManager ЧЕРЕЗ КОТОРЫЙ И БУДЕМ РАБОТАТЬ
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
- }
- protected void onResume() {// В onResume ВЕШАЕМ СЛУШАТЕЛЯ НА ПРОВАЙДЕРА С ПОМОЩЬЮ МЕТОДА requestLocationUpdates
- super.onResume();
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
- // TODO: Consider calling
- // ActivityCompat#requestPermissions
- // here to request the missing permissions, and then overriding
- // public void onRequestPermissionsResult(int requestCode, String[] permissions,
- // int[] grantResults)
- // to handle the case where the user grants the permission. See the documentation
- // for ActivityCompat#requestPermissions for more details.
- return;
- }
- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER/*ТИП ПРОВАЙДЕРА*/,// НА ВХОД ЕМУ ПОДАЁМ
- 1000 * 10/*МИНИМАЛЬНОЕ ВРЕМЯ ЗАПРОСА КООРДИНАТ*/, 10/*РАСТОЯНИЕ ОТОЙДЯ НА КОТОРОЕ ОБНОВЛЯЮТСЯ КООРДИНАТЫ*/, locationListener);
- }
- @Override
- protected void onPause() {//ОТКЛЮЧАЕМ СЛУШАТЕЛЯ МЕТОДА removeUpdates
- super.onPause();
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
- // TODO: Consider calling
- // ActivityCompat#requestPermissions
- // here to request the missing permissions, and then overriding
- // public void onRequestPermissionsResult(int requestCode, String[] permissions,
- // int[] grantResults)
- // to handle the case where the user grants the permission. See the documentation
- // for ActivityCompat#requestPermissions for more details.
- return;
- }
- locationManager.removeUpdates(locationListener);
- }
- private LocationListener locationListener = new LocationListener() {//LocationListener СЛУШАТЕЛЬ РЕАЛИЗУЕТ ИНТЕРФЕЙС locationListener СО СЛЕДУЮЩИМИ МЕТОДАМИ
- @Override
- public void onLocationChanged(Location location) {//МЕТОД onLocationChanged НОВЫЕ ДАННЫЕ О МЕСТО ПОЛОЖЕНИИ
- showLocation(location); //ЗДЕСЬ ВЫЗЫВАЕМ СВОЙ МЕТОД showLocation(location)КОТОРЫЙ НА ЭКРАНЕ ОТОБРОЗИТ ДАННЫЕ О МЕСТО ПОЛОЖЕНИИ
- }
- @Override
- public void onStatusChanged(String provider, int status, Bundle extras) {
- }
- @Override
- public void onProviderDisabled(String provider) {//УКАЗАНЫЙ ПРОВАЙДЕР БЫЛ ОТКЛЮЧОН ПОЛЬЗОВАТЕЛЕМ
- }
- @Override
- public void onProviderEnabled(String provider) {//УКАЗАНЫЙ ПРОВАЙДЕР БЫЛ ВКЛЮЧОН ПОЛЬЗОВАТЕЛЕМ
- }
- };
- private void showLocation(Location location) {// НА ВХОД БЕРЁТ Location location ОПРЕДЕЛЯЕТ ЕГО МЕТОДОМ .getProvider()
- if (location == null)
- return;
- // location.getProvider();
- formatLocation(location);
- }
- private String formatLocation(Location location) {// НА ВХОД БЕРЁТ Location location
- if (location == null) //ЧЕТАЕТ ИЗ НЕГО ДАННЫЕ И ВЫДАЁТ СТРОКУ
- return ""; //ШИРОТА, ДОЛГОТА, ВРЕМЯ ОПРЕДЕЛЕНИЯ
- return String.format(
- "lat = %1$.4f, lon = %2$.4f",
- location.getLatitude(), location.getLongitude());/*, new Date(
- location.getTime()));*/
- }
- DataGPS dataGPS = new DataGPS();
- file = new File(directory.getPath() + "/" + "photo_"
- + timeStamp + dataGPS + ".jpg");
- photo_094127_28062016cod.ru.centre_v00.MainActivity$DataGPS@4222a6b8.jpg
- getClass().getName() + '@' + Integer.toHexString(hashCode())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement