带地图的Kotlin(标记未显示)

时间:2017-07-29 09:33:36

标签: android google-maps 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 个答案:

答案 0 :(得分:1)

  1. 您使用的是错误的地图实例。
  2. Sydney lat lng是-33.8479731,150.6517908
  3. mapFragment?.getMapAsync { 
    
        map ->  // <- this is the map that you got async not mMap            
            val sydney = LatLng(-33.8479731, 150.6517908)
            map.addMarker(...
            map.moveCamera(...
    }