您好,我正在尝试在 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() }
- 您使用了错误的地图实例。
- 悉尼拉特液化天然气正在
-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(... }