Last active
September 21, 2020 07:24
-
-
Save ljcamargo/c235d1dee781ef93ce271d75670835f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.company.maps | |
| import androidx.fragment.app.FragmentActivity | |
| import com.google.android.gms.maps.CameraUpdateFactory | |
| import com.google.android.gms.maps.SupportMapFragment | |
| import com.google.android.gms.maps.model.LatLng | |
| import com.google.android.gms.maps.model.MarkerOptions | |
| import com.google.android.gms.maps.GoogleMap as Map | |
| class AgnosticMap { | |
| private var map: Map? = null | |
| fun startMap( | |
| activity: FragmentActivity, | |
| fragmentId: Int, | |
| latitude: Double, | |
| longitude: Double, | |
| zoom: Float, | |
| marker: Boolean? = true, | |
| ready: (()->Unit)? = null | |
| ) { | |
| val fragment = activity.supportFragmentManager.findFragmentById(fragmentId) | |
| (fragment as? SupportMapFragment)?.apply { | |
| getMapAsync { map -> | |
| this@AgnosticMap.map = map | |
| val point = LatLng(latitude, longitude) | |
| map.apply { | |
| uiSettings.isScrollGesturesEnabled = false | |
| uiSettings.isZoomControlsEnabled = false | |
| uiSettings.isCompassEnabled = false | |
| moveCamera(CameraUpdateFactory.newLatLngZoom(point, zoom)) | |
| if (marker == true) addMarker(MarkerOptions().position(point)) | |
| } | |
| ready?.invoke() | |
| } | |
| } | |
| } | |
| fun setOnMapClickListener(action: ()->Unit) { | |
| map?.setOnMapClickListener { action() } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment