Last active
September 21, 2020 07:25
-
-
Save ljcamargo/c6a451c0dfbd4cd1598be42f08c5244d 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.huawei.hms.maps.CameraUpdateFactory | |
| import com.huawei.hms.maps.SupportMapFragment | |
| import com.huawei.hms.maps.model.LatLng | |
| import com.huawei.hms.maps.model.MarkerOptions | |
| import com.huawei.hms.maps.HuaweiMap 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