Skip to content

Instantly share code, notes, and snippets.

@AlexPrestonSB
Created November 5, 2019 23:07
Show Gist options
  • Save AlexPrestonSB/2cb4d2b79b339dd3cc1f0b34c90518d4 to your computer and use it in GitHub Desktop.
Save AlexPrestonSB/2cb4d2b79b339dd3cc1f0b34c90518d4 to your computer and use it in GitHub Desktop.
Shows the implementation for your CustomViewHolderClass
private val mapView = view.map_gchat_me
/** Initialises the MapView by calling its lifecycle methods */
init {
with(mapView) {
// Initialise the MapView
onCreate(null)
// Set the map ready callback to receive the GoogleMap object
getMapAsync(this@MyLocationHolder)
}
}
fun bindView(context: Context, message: UserMessage, isNewDay: Boolean) {
this.context = context
val cords = message.message.split(",")
longitude = cords[0].toDouble()
latitude = cords[1].toDouble()
latLng = LatLng(latitude, longitude)
setLocation()
}
override fun onMapReady(googleMap: GoogleMap?) {
MapsInitializer.initialize(context.applicationContext)
map = googleMap ?: return
setLocation()
}
private fun setLocation() {
if (!::map.isInitialized) return
with(map) {
moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 11f))
addMarker(MarkerOptions().position(latLng))
mapType = GoogleMap.MAP_TYPE_NORMAL
}
mapView.onResume()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment