|
import com.google.android.gms.maps.model.LatLng
import
|
bet | 13/13 | Sana | 01.07.2022 | Hajmi | 325,71 Kb. | | #721978 |
| Bog'liq b9ElG9exKYpl2zjoqrbhraAGvQ3X7jWQ
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
import uz.bdm.base.R
import uz.bdm.base.base.BaseActivity
import uz.bdm.base.databinding.ActivityMakeOrderBinding
import uz.bdm.base.model.LocationModel
import uz.bdm.base.utils.Prefs
class MakeOrderActivity : BaseActivity(), OnMapReadyCallback {
private lateinit var googleMap: GoogleMap
var locationClient: FusedLocationProviderClient? = null
private var lastLocation = LatLng(0.0,0.0)
override fun getViewBinding(): ActivityMakeOrderBinding =
ActivityMakeOrderBinding.inflate(layoutInflater)
override fun initViews() {
val mapFragment =
supportFragmentManager.findFragmentById(R.id.fallasMap) as SupportMapFragment?
mapFragment?.getMapAsync(this)
binding.imageMap.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN){
binding.scrollView.requestDisallowInterceptTouchEvent(true)
return@setOnTouchListener false
}
if (event.action == MotionEvent.ACTION_UP){
binding.scrollView.requestDisallowInterceptTouchEvent(false)
return@setOnTouchListener true
}
if (event.action == MotionEvent.ACTION_MOVE){
binding.scrollView.requestDisallowInterceptTouchEvent(true)
return@setOnTouchListener false
}
return@setOnTouchListener true
}
locationClient = LocationServices.getFusedLocationProviderClient(this)
binding.back.setOnClickListener {
finish()
}
binding.checkbox.setOnClickListener {
if(binding.checkbox.isChecked){
binding.lySaleOff.visibility = View.VISIBLE
} else {
binding.lySaleOff.visibility = View.GONE
}
}
binding.selfCall.setOnClickListener {
binding.lyDelivery.visibility = View.GONE
binding.selfCall.setBackgroundResource(R.drawable.tip_selected_shape)
binding.selfCall.setTextColor(Color.WHITE )
binding.delivery.setBackgroundResource(R.drawable.tip_unselected_shape)
binding.delivery.setTextColor(Color.BLACK )
}
binding.delivery.setOnClickListener {
binding.lyDelivery.visibility = View.VISIBLE
binding.delivery.setBackgroundResource(R.drawable.tip_selected_shape)
binding.delivery.setTextColor(Color.WHITE )
binding.selfCall.setBackgroundResource(R.drawable.tip_unselected_shape)
binding.selfCall.setTextColor(Color.BLACK )
}
}
override fun loadData() {
}
override fun initData() {
}
override fun updateData() {
}
override fun onMapReady(map: GoogleMap) {
map.let {
googleMap = it
googleMap.resetMinMaxZoomPreference()
if (ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
ActivityCompat.requestPermissions(
this,
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
),
1002
)
return
}
googleMap.isMyLocationEnabled = true
googleMap.uiSettings.isMyLocationButtonEnabled = true
googleMap.uiSettings.isZoomControlsEnabled = true
locationClient?.lastLocation?.addOnCompleteListener {
if(it.result == null){
return@addOnCompleteListener
}
Prefs.setLocation(LocationModel(it.result.latitude, it.result.longitude))
googleMap.animateCamera(
CameraUpdateFactory.newLatLngZoom(
LatLng(it.result.latitude, it.result.longitude),
14.0F
)
)
lastLocation = LatLng(it.result.latitude, it.result.longitude)
googleMap.addMarker(MarkerOptions().position(lastLocation))
}
googleMap.setOnMapLongClickListener { latLng ->
googleMap.clear()
map.addMarker(
MarkerOptions()
.position(latLng)
)
}
}
}
}
Foydalanilgan adabiyotlar.
https://www.w3schools.com/
https://www.youtube.com
https://developer.android.com/.
Do'stlaringiz bilan baham: |
|
|