Raqamli texnologiyalar vazirligi


Download 96.24 Kb.
bet2/2
Sana18.06.2023
Hajmi96.24 Kb.
#1560366
1   2
Ishni bajarish:

Android Studio orqali Google Maps ilovasini ishlab chiqish uchun quyidagi qadamlarni amalga oshirishingiz kerak:


1.API kaliti olish: Google Maps API kalitini olish uchun Google Cloud Platform'da yangi loyiha oching va Google Maps API-sini faollashtiring.
2.Android Studio loyihasini yaratish: Android Studio'ni oching va yangi Android proyekti yarating.
3.Gradle sozlamalari: Proyektning build.gradle faylini oching va dependencies bo'limiga Google Maps API kalitini qo'shing:

4.API kalitini ilovaga integratsiya qilish: Proyektning AndroidManifest.xml faylini oching va application tegi ichiga quyidagi elementini qo'shing. API kalitini android:value atributiga joylang:

5.Google Maps joylashuv komponentini qo'shish: Ishlab chiqish qatormaning activity_main.xml faylini oching va elementini qo'shing. name atributiga com.google.android.gms.maps.SupportMapFragment qiymatini, layout_width va layout_height atributlariga kerakli o'lchamlarni joylang.



6.Google Mapsni loyihada ishlatish: MainActivity.java faylini oching va Google Mapsni ishlatish uchun kerakli kodlarni qo'shing:


Xulosa
Mobil ilovalarda Google Maps ilovasidan foydalanishni o'rganishning asosiy sababi, sizning ilovangizga geografik joylashuv ma'lumotlari, navigatsiya, yo'l tarixi, kartalarni ko'rish va boshqa ma'lumotlar qo'shish imkoniyatlarini qo'shishdir. Bu, sizning ilovangizga qo'shimcha funksiyalar va ma'lumotlar kiritish va foydalanuvchilarga interaktiv kartografiya imkoniyatlarini berishning yo'li hisoblanadi.


Foydalanilgan adabiyotlarlar va internet manbalar

  1. https://cyberleninka.ru/article/n/mobil-ilovalarni-ishlab-chiqishda-qo-llaniladigan-dasturiy-vositalar

  2. https://support.google.com/maps/answer/144349?hl=en&co=GENIE.Platform%3DAndroid

  3. https://www.digitalocean.com/community/tutorials/android-google-maps-example-tutorial


Ilova
private lateinit var fLocationClient : FusedLocationProviderClient
private lateinit var pLauncher : ActivityResultLauncher
private fun permissionListener(){
pLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()){
Toast.makeText(activity, "Permission $it", Toast.LENGTH_SHORT).show()
}
}
private fun checkPermission(){
if (!isPermissionGranted(Manifest.permission.ACCESS_FINE_LOCATION)){
permissionListener()
pLauncher.launch(Manifest.permission.ACCESS_FINE_LOCATION)
}
}
fLocationClient = LocationServices.getFusedLocationProviderClient(requireContext())

private fun getLocation(){


val ct = CancellationTokenSource()

if (ActivityCompat.checkSelfPermission(


requireContext(),
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
requireContext(),
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
){
return
}
fLocationClient.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY,ct.token)
.addOnCompleteListener {
requestWeatherData("${it.result.latitude},${it.result.longitude}")
}
}
private fun checkLocation(){
if (isLocationEnabled()){
getLocation()
}else{
DialogManager.locationSettingDialog(requireContext(),object : DialogManager.Listener{
override fun onClick(name : String?) {
startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))
}
})
}
}

private fun isLocationEnabled() : Boolean{


val lm = activity?.getSystemService(Context.LOCATION_SERVICE) as LocationManager
return lm.isProviderEnabled(LocationManager.GPS_PROVIDER)
}

fun Fragment.isPermissionGranted(p : String) : Boolean{


return ContextCompat.checkSelfPermission(


activity as AppCompatActivity,p
) == PackageManager.PERMISSION_GRANTED
}

Download 96.24 Kb.

Do'stlaringiz bilan baham:
1   2




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