【问题标题】:Kotlin with Map ( Marker Not showing)带地图的 Kotlin(标记未显示)
【发布时间】:2017-07-29 09:33:36
【问题描述】:

您好,我正在尝试在 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() }

【问题讨论】:

  • mapFragment 可能为空,这意味着fragmentManager 找不到它。您是否在代码中的某处初始化了SupportMapFragment
  • 实际上地图显示在屏幕上,但没有添加标记
  • 你能显示你的布局 XML 吗?或者你在某处打电话给SupportMapFragment()(构造函数)?

标签: android google-maps kotlin


【解决方案1】:
  1. 您使用了错误的地图实例。
  2. 悉尼纬度 lng 是-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(...
}

【讨论】:

    猜你喜欢
    • 2016-08-30
    • 2017-01-09
    • 2014-05-17
    • 2019-01-05
    • 2013-07-05
    • 2018-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多