Universiteti “Dasturiy injiniring” fakulteti Mustaqil ishi-1 Mavzu: Mobil ilovalarda geolakatsiyadan foydalanish



Download 355,76 Kb.
bet2/4
Sana31.12.2021
Hajmi355,76 Kb.
#214902
1   2   3   4
Bog'liq
Mobil ilovalarni ishlab chiqish mustaqil ish

koordinatalarni so'raydigan va ko'rsatadigan oddiy dastur yozamiz. Biz loyihani yaratamiz. Strings.xml ga qatorlarni qo'shing:



"provider_gps">GPS
"provider_network">Network
"location_settings">Location settings

"1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp">
android:id="@+id/tvTitleGPS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/provider_gps"
android:textSize="30sp">

android:id="@+id/tvEnabledGPS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp">

android:id="@+id/tvStatusGPS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp">

android:id="@+id/tvLocationGPS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp">

android:id="@+id/tvTitleNet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/provider_network"
android:textSize="30sp">

android:id="@+id/tvEnabledNet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp">

android:id="@+id/tvStatusNet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp">

android:id="@+id/tvLocationNet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp">




MainActivity.java:

package ru.startandroid.develop.p1381location;
import java.util.Date;
import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity {
  TextView tvEnabledGPS;
  TextView tvStatusGPS;
  TextView tvLocationGPS;
  TextView tvEnabledNet;
  TextView tvStatusNet;
  TextView tvLocationNet;
  private LocationManager locationManager;
  StringBuilder sbGPS = new StringBuilder();
  StringBuilder sbNet = new StringBuilder();
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    tvEnabledGPS = (TextView) findViewById(R.id.tvEnabledGPS);
    tvStatusGPS = (TextView) findViewById(R.id.tvStatusGPS);
    tvLocationGPS = (TextView) findViewById(R.id.tvLocationGPS);
    tvEnabledNet = (TextView) findViewById(R.id.tvEnabledNet);
    tvStatusNet = (TextView) findViewById(R.id.tvStatusNet);
    tvLocationNet = (TextView) findViewById(R.id.tvLocationNet);
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);  }
  @Override
  protected void onResume() {
    super.onResume();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
        1000 * 10, 10, locationListener);
    locationManager.requestLocationUpdates(
        LocationManager.NETWORK_PROVIDER, 1000 * 10, 10,
        locationListener);
    checkEnabled();  }
  @Override
  protected void onPause() {
    super.onPause();
    locationManager.removeUpdates(locationListener);  }
  private LocationListener locationListener = new LocationListener() {
    @Override
    public void onLocationChanged(Location location) {
      showLocation(location);    }
    @Override
    public void onProviderDisabled(String provider) {
      checkEnabled();    }
    @Override
    public void onProviderEnabled(String provider) {
      checkEnabled();
      showLocation(locationManager.getLastKnownLocation(provider));    }
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
      if (provider.equals(LocationManager.GPS_PROVIDER)) {
        tvStatusGPS.setText("Status: " + String.valueOf(status));
      } else if (provider.equals(LocationManager.NETWORK_PROVIDER)) {
        tvStatusNet.setText("Status: " + String.valueOf(status));      }
    }
  };
  private void showLocation(Location location) {
    if (location == null)
      return;
    if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) {
      tvLocationGPS.setText(formatLocation(location));
    } else if (location.getProvider().equals(
        LocationManager.NETWORK_PROVIDER)) {
      tvLocationNet.setText(formatLocation(location));
    }
  }
  private String formatLocation(Location location) {
    if (location == null)
      return "";
    return String.format(
      "Coordinates: lat = %1$.4f, lon = %2$.4f, time = %3$tF %3$tT",
        location.getLatitude(), location.getLongitude(), new Date(
            location.getTime()));
  }
  private void checkEnabled() {
    tvEnabledGPS.setText("Enabled: "
        + locationManager
            .isProviderEnabled(LocationManager.GPS_PROVIDER));
    tvEnabledNet.setText("Enabled: "
        + locationManager
            .isProviderEnabled(LocationManager.NETWORK_PROVIDER));  }
  public void onClickLocationSettings(View view) {
    startActivity(new Intent(
        android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));  };
}

OnCreate-da biz TextView komponentlarini aniqlaymiz va LocationManager-ni olamiz, u orqali ishlaymiz.

OnResume-da biz requestLocationUpdates usulidan foydalanamiz. Biz kirish joyiga jo'natamiz:

Location settinglarni sozlashimiz mumkin





2 map methodlari

Agar GPS signalida hammasi yaxshi bo'lsa, unda har 10 soniyada siz o'zingizning joylashuvingiz to'g'risida ma'lumot olasiz. Agar signal yomon bo'lsa, unda ma'lumotlar kamroq kelishi mumkin va holat ba'zida 1 ga o'zgaradi (TEMPORARILY_UNAVAILABLE).

Uchinchi turdagi provayder - PASSIVE_PROVIDER. O'z-o'zidan ushbu provayder hech qanday ma'lumotni qaytarib bermaydi. Ammo tizimdagi boshqa birov oddiy provayderlar orqali joylashuvni aniqlashga harakat qilganda siz joylashuv ma'lumotlarini olishingiz mumkin bo'ladi. Tizim natijalarni siz uchun ham takrorlaydi.

GetAllProviders usuli sizga barcha mavjud provayderlar ro'yxatini qaytaradi. GetProviders (boolean enabledOnly) usuli to'liq yoki faqat yoqilganlarni qaytaradi.

Joylashuv ob'ekti, koordinatalar, vaqt va provayderdan tashqari, bo'sh bo'lishi mumkin bo'lgan yana bir nechta xususiyatlarga ega:

getAccuracy - metrda o'qishning aniqligi

getAltitude - dengiz sathidan metr balandlikda balandlik

getSpeed ​​- harakat tezligi m / s

getBearing - oqim trayektoriyasining traektoriyadan shimolga burilish burchagi.

Joylashuvni AVD emulyatori orqali ham tekshirish mumkin. Buning uchun Eclipse-da DDMS-ni oching (Window> Open Perspective> DDMS) va Emulator Control yorlig'ini tanlang. Pastki qismida Manual yorlig'i joylashgan bo'lib, unda koordinatalarni kiritish joylari va yuborish tugmasi mavjud.

Yana bir qancha methodlar mavjud.Bular

addCircle () Ushbu usul xaritaga doirani qo'shadi.

addPolygon () Ushbu usul xaritaga ko'pburchak qo'shadi.

addTileOverlay () Ushbu usul xaritaga plitka qoplamasini qo'shadi.

animateCamera (Ushbu usul xaritani animatsiya bilan yangilanishga muvofiq ko'chiradi.

clear () Ushbu usul xaritadan hamma narsani olib tashlaydi.

getMyLocation () Ushbu usul hozirda ko'rsatilgan foydalanuvchi manzilini qaytaradi.

Bundan tashqari juda k’op methodlar mavjud ularni batafsil o’rganish uchun

https://www.javatpoint.com/ saytidan ko’rish mumkin

3 Google mapda qilingan dastur



Лойиҳа яратилгандан кейин бепул Google Maps API
калитини жорий иловага ўрнатиш лозим

Dastur tuzishni boshlaymiz



activity_maps.xml

 xmlns:android="http://schemas.android.com/apk/res/android"  

    xmlns:map="http://schemas.android.com/apk/res-auto"  

    xmlns:tools="http://schemas.android.com/tools"  

    android:id="@+id/map"  

    android:name="com.google.android.gms.maps.SupportMapFragment"  

    android:layout_width="match_parent"  

    android:layout_height="match_parent"  

    tools:context="example.com.mapexample.MapsActivity" /> 



Download 355,76 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish