Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin with Map ( Marker Not showing)

Hello I'm trying to implements Google Maps in kotlin, but in these code my getMapAsyncis not getting called, the maps shows perfectly but the marker doesn't show up

    var mapFragment : SupportMapFragment?=null
    mapFragment= fragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
    mapFragment?.getMapAsync { 
        val sydney = LatLng(22.30, 73.20)
        mMap!!.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
        mMap!!.moveCamera(CameraUpdateFactory.newLatLng(sydney))


        Toast.makeText(activity,"dfgdg",Toast.LENGTH_LONG).show() }
like image 785
Dimple patel Avatar asked Jan 25 '26 15:01

Dimple patel


1 Answers

  1. You are using the wrong map instance.
  2. Sydney lat lng are -33.8479731,150.6517908
mapFragment?.getMapAsync { 

    map ->  // <- this is the map that you got async not mMap            
        val sydney = LatLng(-33.8479731, 150.6517908)
        map.addMarker(...
        map.moveCamera(...
}
like image 137
arsent Avatar answered Jan 27 '26 03:01

arsent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!