Kotlin与地图(标记不显示)

你好,我试图在kotlin中实现Google Maps ,但在这些代码中我的getMapAsync没有得到调用,地图显示完美,但标记不显示

  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. 您正在使用错误的地图实例。
  2. 悉尼-33.8479731,150.6517908-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(... }