I want to add a button to my map, every time this button is clicked, I want to turn the camera to a different location. How can I do it? I can't generate a random location What I can do at the moment is the location of the user, adding a listening marker, a number of more operations depending on the location he chose I can do it, I want the camera to go anywhere in the world with the menu key I assigned. How can I do it?
override fun onLocationChanged(p0: Location) {
mMap.clear()
val guncelKonum =LatLng(p0.latitude,p0.longitude)
println("${p0.latitude}"+"${p0.longitude}")
mMap.addMarker(MarkerOptions().position(guncelKonum).title("Guncel Konumunuz"))
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(guncelKonum,12f))
val geocoder =Geocoder(this@MapsActivity, Locale.getDefault())
try {
val adresListesi= geocoder.getFromLocation(p0.latitude,p0.longitude,1)
if (adresListesi.size>0){
println(adresListesi.get(0).toString())
}
}catch (e:Exception){
e.printStackTrace()
}
}
}
if (ContextCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) !=PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),1)
}else {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1,1f,locationListener)
val sonBilinenkonum = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
if (sonBilinenkonum !=null){
val sonbilinenLatLang =LatLng(sonBilinenkonum.latitude,sonBilinenkonum.longitude)
mMap.addMarker(MarkerOptions().position(sonbilinenLatLang).title("Son Bilinen Konumunuz"))
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sonbilinenLatLang,12f))
}
}
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
if (requestCode==1){
if (grantResults.size > 0){
if (ContextCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION)==PackageManager.PERMISSION_GRANTED){
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1,4f,locationListener)
}
}
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
Aucun commentaire:
Enregistrer un commentaire