简体   繁体   中英

Kotlin with Map ( Marker Not showing)

Hello I'm trying to implements Google Maps in kotlin, but in these code my getMapAsync is 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() }
  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(... } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM